/** * Forces the spatial index to be created */ public void createSpatialIndex() throws IOException { buildQuadTree(); }
typeCheck(typeName); existsOrCreateFidIndex(); SimpleFeatureType schema = getSchema(); if (schema == null) { throw new IOException( "To create a shapefile, you must first call createSchema()"); attReader = getAttributesReader(true, true, null, schema); featureReader = createFeatureReader(typeName, attReader, schema); attReader = getAttributesReader(true, true, null, schema); featureReader = new EmptyFeatureReader<SimpleFeatureType, SimpleFeature>(schema);
/** * Creates the spatial index is appropriate. * @param force Forces the index re-creation even if the spatial index seems to be up to date * @return true if the spatial index has been created/updated */ public boolean createSpatialIndex(boolean force) { // create index as needed try { if (shpFiles.isLocal() && createIndex && (needsGeneration(treeType.shpFileType) || force)) { createSpatialIndex(); return true; } } catch (IOException e) { this.treeType = IndexType.NONE; ShapefileDataStoreFactory.LOGGER.log(Level.SEVERE, e .getLocalizedMessage()); } return false; }
/** * Obtain the FeatureType of the given name. ShapefileDataStore contains * only one FeatureType. * * @param typeName * The name of the FeatureType. * * @return The FeatureType that this DataStore contains. * * @throws IOException * If a type by the requested name is not present. */ public FeatureType getSchema(String typeName) throws IOException { typeCheck(typeName); return getSchema(); }
final FeatureType featureType = getSchema(typeName); if (getLockingManager() != null) { return new AbstractFeatureLocking() { public DataStore getDataStore() {
/** * If the fid index can be used and it is missing this method will try to create it * @return */ boolean existsOrCreateFidIndex() { if(indexUseable(ShpFileType.FIX)) { return true; } else { if(isLocal()) { try { FidIndexer.generate(shpFiles); return true; } catch(IOException e) { LOGGER.log(Level.WARNING, "Failed to create fid index"); return false; } } else { return false; } } }
throws IOException { if (query.getFilter() == Filter.EXCLUDE) return new EmptyFeatureReader<SimpleFeatureType, SimpleFeature>(getSchema()); .equals(defaultGeomName))) { readDbf = false; newSchema = createSubType( propertyNames); } else if ((query.getPropertyNames() == Query.NO_NAMES) && (propertyNames.length == 0)) { readDbf = false; readGeometry = false; newSchema = createSubType( propertyNames); } else if( propertyNames.length > 0 && !propertyNames[0].equals(defaultGeomName) ){ readGeometry = false; newSchema = createSubType(propertyNames); } else if(propertyNames.length > 0) { newSchema = createSubType(propertyNames); return createFeatureReader(typeName, getAttributesReader(readDbf, readGeometry, query, newSchema), newSchema); } catch (SchemaException se) {
attReader = getAttributesReader(true, true, null); featureReader = createFeatureReader(typeName, attReader, schema); } catch (Exception e) { FeatureType schema = getSchema(typeName); new IndexedFidReader(getCurrentTypeName(), temp!=0?getReadChannel(fixURL):fidIndexChannel));
Filter filter = query.getFilter(); if (filter == Filter.INCLUDE || query == Query.ALL) { return getBounds(); List<Data> recordsFound = queryFidIndex(fids); if (recordsFound != null) { records.addAll(recordsFound); ret = new ReferencedEnvelope(getSchema().getCoordinateReferenceSystem()); for (Iterator iter = records.iterator(); iter.hasNext();) { Data data = (Data) iter.next();
try { File indexFile = new File(fixURL.getFile()); if (isLocal()) { synchronized (FIX_LOCK) { if( indexFile.exists() && !isIndexed(fixURL) ){ if( !indexFile.delete() ){ indexFile.deleteOnExit(); reader = new IndexedFidReader(getCurrentTypeName(), getReadChannel(fixURL)); if (reader.getRemoves() >= reader.getCount() / 2) { indexFile.deleteOnExit(); IndexFile shx = openIndexFile(shxURL); try {
public FeatureWriter getFeatureWriterAppend(String typeName, Transaction transaction) throws IOException { if (transaction == null) { throw new NullPointerException( "getFeatureWriter requires Transaction: " + "did you mean to use Transaction.AUTO_COMMIT?"); } FeatureWriter writer; if (transaction == Transaction.AUTO_COMMIT) { return super.getFeatureWriterAppend(typeName, transaction); } else { writer = state(transaction).writer(typeName, Filter.EXCLUDE); } if (getLockingManager() != null) { // subclass has not provided locking so we will // fake it with InProcess locks writer = ((InProcessLockingManager) getLockingManager()).checkedWriter(writer, transaction); } while(writer.hasNext() ) writer.next(); return writer; }
throws IOException { if( query.getFilter()==Filter.EXCLUDE ) return new EmptyFeatureReader(getSchema()); return createFeatureReader(typeName, getAttributesReader(readDbf, readGeometry, query.getFilter()), newSchema); } catch (SchemaException se) {
return getBounds(); } else if (this.useIndex) { if (treeType == TREE_GRX) { return getBoundsRTree(query); Filters.accept(query.getFilter(), visitor); if( !visitor.fids.isEmpty() ) { List recordsFound = queryFidIndex((String[]) visitor.fids.toArray(new String[0])); if( recordsFound!=null ) records.addAll(recordsFound); return null; ShapefileReader reader=new ShapefileReader(getReadChannel(shpURL), this.readWriteLock); try{ ret=new Envelope();
protected FeatureReader<SimpleFeatureType, SimpleFeature> createFeatureReader(String typeName, IndexedShapefileAttributeReader r, SimpleFeatureType readerSchema) throws SchemaException, IOException { if(r == null) { return new EmptyFeatureReader<SimpleFeatureType, SimpleFeature>(readerSchema); } FIDReader fidReader; if (!indexUseable(FIX)) { fidReader = new ShapeFIDReader(getCurrentTypeName(), r); } else { fidReader = new IndexedFidReader(shpFiles, r); } return new org.geotools.data.FIDFeatureReader(r, fidReader, readerSchema); }
createSpatialIndex(false); QuadTree quadTree = openQuadTree(); if(quadTree != null) { LOGGER.warning("Experimental: loading in memory the quadtree for " + shpFiles.get(SHP)); QuadTree quadTree = openQuadTree(); if ((quadTree != null) && !bbox.contains(quadTree.getRoot().getBounds())) {
if (!indexUseable(FIX)) { return null; IndexFile shx = openIndexFile(); try {
if( treeFile.exists() && !isIndexed(treeURL) ){ if( !treeFile.delete() ){ createIndex=false; if (this.createIndex) { try { this.buildQuadTree(maxDepth); } catch (Throwable e) { createIndex=false; quadTree = store.load(openIndexFile(shxURL)); } catch (IOException e) { throw new StoreException(e);
/** * DOCUMENT ME! * * @param typeName * @param r * @param readerSchema * * * @throws SchemaException * @throws IOException */ protected FeatureReader createFeatureReader(String typeName, Reader r, FeatureType readerSchema) throws SchemaException, IOException { if (isLocal() && fixURL!=null ) { if (!(new File(fixURL.getFile()).exists())) fixURL=FidIndexer.generate(shpURL); if( fixURL==null ) return new org.geotools.data.FIDFeatureReader(r, new ShapeFIDReader(getCurrentTypeName(), r), readerSchema); return new org.geotools.data.FIDFeatureReader(r, new IndexedFidReader(getCurrentTypeName(), r, getReadChannel(fixURL)), readerSchema); } else { return new org.geotools.data.FIDFeatureReader(r, new ShapeFIDReader(getCurrentTypeName(), r), readerSchema); } }
/** * Release resources and flush the header information. */ public void close() throws IOException { super.close(); fidWriter.close(); try { if (shpFiles.isLocal()) { if (indexedShapefileDataStore.needsGeneration(ShpFileType.FIX)) { FidIndexer.generate(shpFiles); } deleteFile(ShpFileType.QIX); if (indexedShapefileDataStore.treeType == IndexType.QIX) { indexedShapefileDataStore.buildQuadTree(); } } } catch (Throwable e) { indexedShapefileDataStore.treeType = IndexType.NONE; ShapefileDataStoreFactory.LOGGER.log(Level.WARNING, "Error creating Spatial index", e); } }
/** * Get an array of type names this DataStore holds.<BR/>ShapefileDataStore * will always return a single name. * * @return An array of length one containing the single type held. */ public String[] getTypeNames() { return new String[] { getCurrentTypeName(), }; }