Hi Wade:  GeoTools tends to not load your shapefile into memory (so
that you can work on massive shapefiles). It supports the disk base
QNX spatial index; and is very quick.

I have long wanted to make an in memory "FeatureCollection" that used
a JTS spatial index but have not had the chance. As you are aware
there are two spatial indexes in JTS ....

Please remember that the features you get back from a shapefile is not
really yours to keep -  ie these are data objects and are not located
in the same process as your Java program - they are located on disk or
in your database.

Jody

On Tue, Jul 14, 2009 at 12:35 AM, <[email protected]> wrote:
> Hi all,
>
> I caught a typo in my code snippet that I just sent regarding the spatial
> query.  It should have read where location replaces newGeometry:
>
>     Geometry geom = (Geometry)
>  feature.getAttribute(schema.getGeometryDescriptor().getLocalName());
>     if (location.intersects(geom)) {
>       fCollection.add(feature);
>     }
>   }
>
> I was cutting and pasting and put the wrong snippet in the email, so this
> typo did not cause the problem i'm experiencing.
>
> Sorry about the possible confusion,
> Wade
>
>
>
>> Hi all,
>>
>> I’m attempting to run a program that dynamically adds and modifies
>> features in a shapefile, where I decide on which features get modified
>> through a spatial index query with a Quadtree.
>>
>> When testing the code, if I:
>>
>> (1) create a new feature,
>>
>>   fStore.addFeatures(DataUtilities.collection( newFeature ));
>>   spatialIndex.insert( bounds, newFeature );
>>
>> (2) query that feature’s location (spatialIndex.query(…)) to get the
>> feature, and then
>>
>> (3) try to remove that feature in the same instance (through
>> featureStore.removeFeatures()),
>>
>> It creates the feature fine, but doesn’t remove it.  However, if I run two
>> separate instances of my class where I create the feature in the first,
>> and then remove it in the second, it works fine.  E.g.,
>>
>>   MyFeatureClass mfc = new MyFeatureClass ();
>>   mfc.createFeature();
>>   MyFeatureClass mfc2 = new MyFeatureClass ();
>>   mfc2.modifyFeature();
>>
>>
>> Checking into this further, I noticed that this only happens in my code
>> when I use the Quadtree spatial index to query my features.  E.g., if I
>> query my spatial index based on the coordinate of where I created my new
>> feature,
>>
>>   Point location = geofactory.createPoint(coord);
>>   List<SimpleFeature> hits =
>> spatialIndex.query(location.getEnvelopeInternal());
>>   SimpleFeature feature;
>>   for (int i = 0; i < hits.size(); i++) {
>>     feature= hits.get(i);
>>     Geometry geom = (Geometry)
>> feature.getAttribute(schema.getGeometryDescriptor().getLocalName());
>>     if (newGeometry.intersects(geom)) {
>>       fCollection.add(feature);
>>     }
>>   }
>>
>>   Set<FeatureId> removeFeatureSet = new HashSet<FeatureId>();
>>   FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2( null );
>>
>>   iterator = fCollection.features();
>>   while( iterator.hasNext()){
>>     SimpleFeature feature = iterator.next();
>>     removeFeatureSet.add( ff.featureId(feature.getID()));
>>     spatialIndex.remove( bounds, feature );
>>   }
>>   removeFilter = ff.id( removeFeatureSet);
>>   fStore.removeFeatures(removeFilter);
>>
>>
>>
>> Alternatively, if I query my to-remove features straight from the feature
>> source instead of getting them from the spatial index, it works fine.
>> E.g.,
>>
>>   Filter filter= ff.intersects(ff.property(geometryPropertyName),
>> ff.literal(newGeometry));
>>   fCollection = fSource.getFeatures( filter );
>>   …(as above)… removeFeatures(removeFilter);
>>
>> I would like to use a Spatial Index for querying because I’ll be doing a
>> lot of location-based queries for features on a large dataset, but I also
>> need to modify the shapefile frequently.  Can the JTS Quadtree be used to
>> query and return features that will then get modified in the same
>> instance?  Or do I need to get features straight from the feature source
>> insead of the spatial index when modifying?  If anyone has any suggestions
>> I would greatly appreciate it.  I can send the full code if anyone would
>> like to see.
>>
>> Thanks,
>> Wade
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Enter the BlackBerry Developer Challenge
>> This is your chance to win up to $100,000 in prizes! For a limited time,
>> vendors submitting new applications to BlackBerry App World(TM) will have
>> the opportunity to enter the BlackBerry Developer Challenge. See full
>> prize
>> details at: http://p.sf.net/sfu/Challenge
>> _______________________________________________
>> Geotools-gt2-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>>
>
>
>
> ------------------------------------------------------------------------------
> Enter the BlackBerry Developer Challenge
> This is your chance to win up to $100,000 in prizes! For a limited time,
> vendors submitting new applications to BlackBerry App World(TM) will have
> the opportunity to enter the BlackBerry Developer Challenge. See full prize
> details at: http://p.sf.net/sfu/Challenge
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to