Revision 38581 branches/v2_0_0_prep/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/layers/vectorial/FLyrVect.java

View differences:

FLyrVect.java
143 143
    public FLyrVect() {
144 144
        super();
145 145
    }
146
    
147
	public String getTocImageIcon() {
148
		return MapContextLocator.getMapContextManager().getIconLayer(this.getDataStore());
149
	}
146 150

  
147 151
    /**
148 152
     * Devuelve el VectorialAdapater de la capa.
......
156 160
        return featureStore;
157 161
    }
158 162
    
159
//    public void setCoordTrans(ICoordTrans ct) {
160
//    	super.setCoordTrans(ct);
161
//    	if (ct != null){
162
//    		if (this.reprojectTransform == null){
163
//    			this.reprojectTransform = new ReprojectDefaultGeometry(ct);
164
//    		} else {
165
//    			this.reprojectTransform.setCoordTrans(ct);
166
//    		}
167
//    		try {
168
//    			this.getFeatureStore().getTransforms().add(this.reprojectTransform);
169
//    		} catch (DataException e) {
170
//    			throw new RuntimeException(e);
171
//    		}
172
//    	}
173
//    }
174

  
175 163
    /**
176
     * If we use a persistent spatial index associated with this layer, and the
177
     * index is not intrisic to the layer (for example spatial databases) this
178
     * method looks for existent spatial index, and loads it.
164
     * Inserta el DataStore a la capa.
179 165
     * 
180
     */
181
    // private void loadSpatialIndex() {
182
    // //FIXME: Al abrir el indice en fichero...
183
    // //?C?mo lo liberamos? un metodo Layer.shutdown()
184
    //
185
    //
186
    // ReadableVectorial source = getSource();
187
    // //REVISAR QUE PASA CON LOS DRIVERS DXF, DGN, etc.
188
    // //PUES SON VECTORIALFILEADAPTER
189
    // if (!(source instanceof VectorialFileAdapter)) {
190
    // // we are not interested in db adapters
191
    // return;
192
    // }
193
    // VectorialDriver driver = source.getDriver();
194
    // if (!(driver instanceof BoundedShapes)) {
195
    // // we dont spatially index layers that are not bounded
196
    // return;
197
    // }
198
    // File file = ((VectorialFileAdapter) source).getFile();
199
    // String fileName = file.getAbsolutePath();
200
    // File sptFile = new File(fileName + ".qix");
201
    // if (!sptFile.exists() || (!(sptFile.length() > 0))) {
202
    // // before to exit, look for it in temp path
203
    // String tempPath = System.getProperty("java.io.tmpdir");
204
    // fileName = tempPath + File.separator + sptFile.getName();
205
    // sptFile = new File(fileName);
206
    // // it doesnt exists, must to create
207
    // if (!sptFile.exists() || (!(sptFile.length() > 0))) {
208
    // return;
209
    // }// if
210
    // }// if
211
    //
212
    // try {
213
    // source.start();
214
    // spatialIndex = new
215
    // QuadtreeGt2(FileUtils.getFileWithoutExtension(sptFile),
216
    // "NM", source.getFullExtent(), source.getShapeCount(), false);
217
    // source.setSpatialIndex(spatialIndex);
218
    // } catch (SpatialIndexException e) {
219
    // spatialIndex = null;
220
    // e.printStackTrace();
221
    // return;
222
    // } catch (ReadDriverException e) {
223
    // spatialIndex = null;
224
    // e.printStackTrace();
225
    // return;
226
    // }
227
    //
228
    // }
229

  
230
    /**
231
     * Checks if it has associated an external spatial index
232
     * (an spatial index file).
233
     * 
234
     * It looks for it in main file path, or in temp system path.
235
     * If main file is rivers.shp, it looks for a file called
236
     * rivers.shp.qix.
237
     * 
238
     * @return
239
     */
240
    // public boolean isExternallySpatiallyIndexed() {
241
    // /*
242
    // * FIXME (AZABALA): Independizar del tipo de fichero de ?ndice
243
    // * con el que se trabaje (ahora mismo considera la extension .qix,
244
    // * pero esto depender? del tipo de ?ndice)
245
    // * */
246
    // ReadableVectorial source = getSource();
247
    // if (!(source instanceof VectorialFileAdapter)) {
248
    // // we are not interested in db adapters.
249
    // // think in non spatial dbs, like HSQLDB
250
    // return false;
251
    // }
252
    // File file = ((VectorialFileAdapter) source).getFile();
253
    // String fileName = file.getAbsolutePath();
254
    // File sptFile = new File(fileName + ".qix");
255
    // if (!sptFile.exists() || (!(sptFile.length() > 0))) {
256
    // // before to exit, look for it in temp path
257
    // // it doesnt exists, must to create
258
    // String tempPath = System.getProperty("java.io.tmpdir");
259
    // fileName = tempPath + File.separator + sptFile.getName();
260
    // sptFile = new File(fileName);
261
    // if (!sptFile.exists() || (!(sptFile.length() > 0))) {
262
    // return false;
263
    // }// if
264
    // }// if
265
    // return true;
266
    // }
267
    /**
268
     * Inserta el VectorialAdapter a la capa.
269
     * 
270 166
     * @param va
271 167
     *            VectorialAdapter.
272 168
     * 
......
336 232
        	rAux = rAux.convert(ct);
337 233
        }
338 234
        return rAux;
235

  
339 236
    }
340 237

  
341 238
    /**
......
439 336
        }
440 337
    }
441 338

  
442
    /**
443
     * <p>
444
     * Creates an spatial index associated to this layer. The spatial index will
445
     * used the native projection of the layer, so if the layer is reprojected,
446
     * it will be ignored.
447
     * </p>
448
     * 
449
     * @param cancelMonitor
450
     *            instance of CancellableMonitorable that allows
451
     *            to monitor progress of spatial index creation, and cancel the
452
     *            process
453
     */
454
    // public void createSpatialIndex(CancellableMonitorable cancelMonitor){
455
    // // FJP: ESTO HABR? QUE CAMBIARLO. PARA LAS CAPAS SECUENCIALES, TENDREMOS
456
    // // QUE ACCEDER CON UN WHILE NEXT. (O mejorar lo de los FeatureVisitor
457
    // // para que acepten recorrer sin geometria, solo con rectangulos.
458
    //
459
    // //If this vectorial layer is based in a spatial database, the spatial
460
    // //index is already implicit. We only will index file drivers
461
    // ReadableVectorial va = getSource();
462
    // //We must think in non spatial databases, like HSQLDB
463
    // if(!(va instanceof VectorialFileAdapter)){
464
    // return;
465
    // }
466
    // if (!(va.getDriver() instanceof BoundedShapes)) {
467
    // return;
468
    // }
469
    // File file = ((VectorialFileAdapter) va).getFile();
470
    // String fileName = file.getAbsolutePath();
471
    // ISpatialIndex localCopy = null;
472
    // try {
473
    // va.start();
474
    // localCopy = new QuadtreeGt2(fileName, "NM", va.getFullExtent(),
475
    // va.getShapeCount(), true);
476
    //
477
    // } catch (SpatialIndexException e1) {
478
    // // Probably we dont have writing permissions
479
    // String directoryName = System.getProperty("java.io.tmpdir");
480
    // File newFile = new File(directoryName +
481
    // File.separator +
482
    // file.getName());
483
    // String newFileName = newFile.getName();
484
    // try {
485
    // localCopy = new QuadtreeGt2(newFileName, "NM", va.getFullExtent(),
486
    // va.getShapeCount(), true);
487
    // } catch (SpatialIndexException e) {
488
    // // if we cant build a file based spatial index, we'll build
489
    // // a pure memory spatial index
490
    // localCopy = new QuadtreeJts();
491
    // } catch (ReadException e) {
492
    // localCopy = new QuadtreeJts();
493
    // }
494
    //
495
    // } catch(Exception e){
496
    // e.printStackTrace();
497
    // }//try
498
    // BoundedShapes shapeBounds = (BoundedShapes) va.getDriver();
499
    // try {
500
    // for (int i=0; i < va.getShapeCount(); i++)
501
    // {
502
    // if(cancelMonitor != null){
503
    // if(cancelMonitor.isCanceled())
504
    // return;
505
    // cancelMonitor.reportStep();
506
    // }
507
    // Rectangle2D r = shapeBounds.getShapeBounds(i);
508
    // if(r != null)
509
    // localCopy.insert(r, i);
510
    // } // for
511
    // va.stop();
512
    // if(localCopy instanceof IPersistentSpatialIndex)
513
    // ((IPersistentSpatialIndex) localCopy).flush();
514
    // spatialIndex = localCopy;
515
    // //vectorial adapter needs a reference to the spatial index, to solve
516
    // //request for feature iteration based in spatial queries
517
    // source.setSpatialIndex(spatialIndex);
518
    // } catch (ReadException e) {
519
    // // TODO Auto-generated catch block
520
    // e.printStackTrace();
521
    // }
522
    // }
523

  
524
    // public void createSpatialIndex() {
525
    // createSpatialIndex(null);
526
    // }
527

  
528 339
    public void setLegend(IVectorLegend legend) throws LegendLayerException {
529 340
        if (this.legend == legend) {
530 341
            return;
......
633 444
        state.set("typeShape", typeShape);
634 445
    }
635 446

  
636
    // public XMLEntity getXMLEntity() throws XMLException {
637
    //
638
    // if (!this.isAvailable() && this.orgXMLEntity != null) {
639
    // return this.orgXMLEntity;
640
    // }
641
    // XMLEntity xml = super.getXMLEntity();
642
    // if (getLegend()!=null){
643
    // XMLEntity xmlLegend=getLegend().getXMLEntity();
644
    // xmlLegend.putProperty("tagName","legend");
645
    // xml.addChild(xmlLegend);
646
    // }
647
    // try {
648
    // PersistenceManager manager = ToolsLocator.getPersistenceManager();
649
    // PersistentState stateFeatureStore=manager.getState(getFeatureStore());
650
    // stateFeatureStore.set("tagName","featureStore");
651
    // xml.addChild(((XMLEntityState)stateFeatureStore).getXMLEntity());
652
    // } catch (ReadException e) {
653
    // throw new XMLLayerException(getName(),e);
654
    // } catch (PersistenceException e) {
655
    // throw new XMLLayerException(getName(),e);
656
    // }
657
    // // properties from ILabelable
658
    // xml.putProperty("isLabeled", isLabeled);
659
    // if (strategy != null) {
660
    // XMLEntity strategyXML = strategy.getXMLEntity();
661
    // strategyXML.putProperty("tagName", "labelingStrategy");
662
    // xml.addChild(strategy.getXMLEntity());
663
    // }
664
    // xml.addChild(getLinkProperties().getXMLEntity());
665
    // return xml;
666
    // }
667 447

  
668 448
    public void loadFromState(PersistentState state) throws PersistenceException {
669 449

  
......
716 496
            this.setLabelingStrategy(null);
717 497
        }
718 498

  
719
        // try {
720
        // linkProperties = (FLyrVectLinkProperties)
721
        // state.get("linkProperties");
722
        // } catch (PersistenceException pex) {
723
        // // not mandatory
724
        // linkProperties = null;
725
        // }
726

  
727
        // bHasJoin = state.getBoolean("bHasJoin");
728 499
        typeShape = state.getInt("typeShape");
729 500

  
730
        // try { _labelFieldName = state.getString("labelFieldName"); } catch
731
        // (PersistenceException ex) {
732
        // _labelFieldName = null;
733
        // }
734
        // try { _labelfield = state.getString("labelfield"); } catch
735
        // (PersistenceException ex) {
736
        // _labelfield = null;
737
        // }
738

  
739
        // ILabelingStrategy not implemented
740
        // if (_labelFieldName != null) {
741
        //
742
        // AttrInTableLabelingStrategy labeling = new
743
        // AttrInTableLabelingStrategy();
744
        // try {
745
        // labeling.setLayer(this);
746
        // } catch (ReadException e) {
747
        // logger.error("While setting layer to AttrInTableLabelingStrategy: " +
748
        // e.getMessage());
749
        // }
750
        // labeling.setUsesFixedSize(true);
751
        // labeling.setFixedSize(10);
752
        // labeling.setTextField(_labelFieldName);
753
        // labeling.setHeightField(state.getString("labelHeightFieldName"));
754
        // labeling.setRotationField(state.getString("labelRotationFieldName"));
755
        // setLabelingStrategy(labeling);
756
        // setIsLabeled(true);
757
        //
758
        // } else {
759
        // if (_labelfield != null) {
760
        //
761
        // AttrInTableLabelingStrategy labeling = new
762
        // AttrInTableLabelingStrategy();
763
        // try {
764
        // labeling.setLayer(this);
765
        // } catch (ReadException e) {
766
        // logger.error("While setting layer to AttrInTableLabelingStrategy: " +
767
        // e.getMessage());
768
        // }
769
        // labeling.setUsesFixedSize(true);
770
        // labeling.setFixedSize(10);
771
        // labeling.setTextField(_labelfield);
772
        // labeling.setHeightField(state.getString("labelFieldHeight"));
773
        // labeling.setRotationField(state.getString("labelFieldRotation"));
774
        // setLabelingStrategy(labeling);
775
        // setIsLabeled(true);
776
        // }
777
        // }
778

  
779 501
    }
780 502

  
781
    // public void setXMLEntity(XMLEntity xml) throws XMLException {
782
    // try {
783
    // super.setXMLEntity(xml);
784
    // XMLEntity legendXML = xml.firstChild("tagName","legend");
785
    // IVectorLegend leg = LegendFactory.createFromXML(legendXML);
786
    //
787
    // // PersistentState persistentState=new XMLEntityState(new
788
    // XMLEntityManager());
789
    // XMLEntity xmlStore=xml.firstChild("tagName","featureStore");
790
    // XMLEntityManager xmlManger = new XMLEntityManager();
791
    // PersistentState state = xmlManger.createState(xmlStore);
792
    // DataStore store = (DataStore)
793
    // ToolsLocator.getPersistenceManager().create(state);
794
    // // persistentState.createState(xmlStore);
795
    //
796
    // // DataManager dm=DALLocator.getDataManager();
797
    //
798
    // this.setDataStore(store);
799
    // /* end patch */
800
    // try {
801
    // setLegend(leg);
802
    // } catch (LegendLayerException e) {
803
    // throw new XMLLegendException(e);
804
    // }
805
    // // set properties for ILabelable
806
    //
807
    // if (xml.contains("isLabeled")
808
    // && xml.getBooleanProperty(("isLabeled"))) {
809
    // XMLEntity labelingXML = xml.firstChild("tagName", "labelingStrategy");
810
    // if (labelingXML != null){
811
    //
812
    // isLabeled = true;
813
    // try {
814
    // this.strategy = LabelingFactory.createStrategyFromXML(labelingXML, this);
815
    // } catch (NotExistInXMLEntity neXMLEX) {
816
    // // no strategy was set, just continue;
817
    // logger.warn("Reached what should be unreachable code");
818
    // }
819
    // } else {
820
    // isLabeled = false;
821
    // }
822
    // } else if (legendXML.contains("labelFieldName")||
823
    // legendXML.contains("labelfield")) {
824
    // /* (jaume) begin patch;
825
    // * for backward compatibility purposes. Since gvSIG v1.1 labeling is
826
    // * no longer managed by the Legend but by the ILabelingStrategy. The
827
    // * following allows restoring older projects' labelings.
828
    // */
829
    // String labelTextField = null;
830
    // if (legendXML.contains("labelFieldName")){
831
    // labelTextField = legendXML.getStringProperty("labelFieldName");
832
    // if (labelTextField != null) {
833
    // AttrInTableLabelingStrategy labeling = new AttrInTableLabelingStrategy();
834
    // labeling.setLayer(this);
835
    // labeling.setUsesFixedSize(true);
836
    // labeling.setFixedSize(10);
837
    // labeling.setTextField(labelTextField);
838
    // labeling.setHeightField(legendXML.getStringProperty("labelHeightFieldName"));
839
    // labeling.setRotationField(legendXML.getStringProperty("labelRotationFieldName"));
840
    // this.setLabelingStrategy(labeling);
841
    // this.setIsLabeled(true);
842
    // }
843
    // }else{
844
    // labelTextField = legendXML.getStringProperty("labelfield");
845
    // if (labelTextField != null) {
846
    // AttrInTableLabelingStrategy labeling = new AttrInTableLabelingStrategy();
847
    // labeling.setLayer(this);
848
    // labeling.setUsesFixedSize(true);
849
    // labeling.setFixedSize(10);
850
    // labeling.setTextField(labelTextField);
851
    // labeling.setHeightField(legendXML.getStringProperty("labelFieldHeight"));
852
    // labeling.setRotationField(legendXML.getStringProperty("labelFieldRotation"));
853
    // this.setLabelingStrategy(labeling);
854
    // this.setIsLabeled(true);
855
    // }
856
    // }
857
    // }else{
858
    // isLabeled = false;
859
    // }
860
    // XMLEntity xmlLinkProperties=xml.firstChild("typeChild","linkProperties");
861
    // if (xmlLinkProperties != null){
862
    // getLinkProperties().setXMLEntity(xmlLinkProperties);
863
    // }
864
    // } catch (Exception e) {
865
    // e.printStackTrace();
866
    // this.setAvailable(false);
867
    // this.orgXMLEntity = xml;
868
    //
869
    // }
870
    // //
871
    //
872
    // }
873

  
874 503
    /**
875 504
     * Sobreimplementaci?n del m?todo toString para que las bases de datos
876 505
     * identifiquen la capa.
......
887 516
        return "layer" + ret.substring(ret.indexOf('@') + 1);
888 517
    }
889 518

  
890
    // public boolean isJoined() {
891
    // return bHasJoin;
892
    // }
893

  
894
    /**
895
     * Returns if a layer is spatially indexed
896
     * 
897
     * @return if this layer has the ability to proces spatial queries without
898
     *         secuential scans.
899
     * @throws StopEditionLayerException 
900
     */
901
    // public boolean isSpatiallyIndexed() {
902
    // ReadableVectorial source = getSource();
903
    // if (source instanceof ISpatialDB)
904
    // return true;
905
    //
906
    // //FIXME azabala
907
    // /*
908
    // * Esto es muy dudoso, y puede cambiar.
909
    // * Estoy diciendo que las que no son fichero o no son
910
    // * BoundedShapes estan indexadas. Esto es mentira, pero
911
    // * as? quien pregunte no querr? generar el indice.
912
    // * Esta por ver si interesa generar el indice para capas
913
    // * HSQLDB, WFS, etc.
914
    // */
915
    // if(!(source instanceof VectorialFileAdapter)){
916
    // return true;
917
    // }
918
    // if (!(source.getDriver() instanceof BoundedShapes)) {
919
    // return true;
920
    // }
921
    //
922
    // if (getISpatialIndex() != null)
923
    // return true;
924
    // return false;
925
    // }
926
    //
927
    // public void setIsJoined(boolean hasJoin) {
928
    // bHasJoin = hasJoin;
929
    // }
930

  
931
    // /**
932
    // * @return Returns the spatialIndex.
933
    // */
934
    // public ISpatialIndex getISpatialIndex() {
935
    // return spatialIndex;
936
    // }
937
    // /**
938
    // * Sets the spatial index. This could be useful if, for some
939
    // * reasons, you want to work with a distinct spatial index
940
    // * (for example, a spatial index which could makes nearest
941
    // * neighbour querys)
942
    // * @param spatialIndex
943
    // */
944
    // public void setISpatialIndex(ISpatialIndex spatialIndex){
945
    // this.spatialIndex = spatialIndex;
946
    // }
947

  
948 519
    public void setEditing(boolean b) throws StartEditionLayerException {
949 520
        super.setEditing(b);
950 521
        FeatureStore fs = getFeatureStore();
......
1135 706
        return onePoint;
1136 707
    }
1137 708

  
1138
    /*
1139
     * jaume. Stuff from ILabeled.
1140
     */
1141

  
1142 709
    public boolean isLabeled() {
1143 710
        return isLabeled;
1144 711
    }
......
1181 748
        }
1182 749
    }
1183 750

  
1184
    // M?todos para el uso de HyperLinks en capas FLyerVect
1185

  
1186 751
    /**
1187 752
     * Return true, because a Vectorial Layer supports HyperLink
753
     * 
754
     * @deprecated the hiperlink functionaliti is out the layer now
1188 755
     */
1189 756
    public boolean allowLinks() {
1190
        return true;
757
        return false;
1191 758
    }
1192 759

  
1193
    /**
1194
     * Returns an instance of AbstractLinkProperties that contains the
1195
     * information
1196
     * of the HyperLink
1197
     * 
1198
     * @return Abstra
1199
     */
1200
    // public AbstractLinkProperties getLinkProperties()
1201
    // {
1202
    // return linkProperties;
1203
    // }
1204

  
1205
    /**
1206
     * Provides an array with URIs. Returns one URI by geometry that includes
1207
     * the point
1208
     * in its own geometry limits with a allowed tolerance.
1209
     * 
1210
     * @param layer
1211
     *            , the layer
1212
     * @param point
1213
     *            , the point to check that is contained or not in the
1214
     *            geometries in the layer
1215
     * @param tolerance
1216
     *            , the tolerance allowed. Allowed margin of error to detect if
1217
     *            the point
1218
     *            is contained in some geometries of the layer
1219
     * @return
1220
     * @throws ReadException
1221
     * @throws BehaviorException
1222
     */
1223
    // public URI[] getLink(Point2D point, double tolerance) throws
1224
    // ReadException
1225
    // {
1226
    // //return linkProperties.getLink(this)
1227
    // return linkProperties.getLink(this,point,tolerance);
1228
    // }
1229

  
1230 760
    public void load() throws LoadLayerException {
1231 761
        super.load();
1232 762
    }

Also available in: Unified diff