Hello,
I found that if I changed the filter from
filter = ff2.intersects(ff2.property(poigeometryAttributeName),
ff2.literal(bbox));
to
filter = ff2.bbox(ff2.property(poigeometryAttributeName), bbox);
No exception is raised and the correct set of features is returned.
Hal
From: Hal Mirsky [mailto:[email protected]]
Sent: Wednesday, September 11, 2013 5:22 PM
To: 'geotools users'
Subject: null pointer expection in ShapefileFeatureSource
Hello,
I just upgraded from 9.5 to 10-RC2 and am getting a Null Pointer Exception.
The routine runs without error under 9.5 but generates an exception on this
line (from code below) under 10-RC2:
System.out.println(selectedFeatures.size());
The stack trace shows the exception is on line 237 of
ShapefileFeatureSource:
} else if (getDataStore().isIndexed() && !bbox.isNull()
The function below is called upon a mouse release event. It is passed the
mouse click and mouse release positions, creates a bbox from the points and
selects features using an intersects filter. Here's the code and error.
Any suggestions would be very much appreciated.
public Set<FeatureId> selectPOIs(DirectPosition2D startPos,
DirectPosition2D endPos)
{
System.out.println("start: " + startPos.toString());
System.out.println("end: " + endPos.toString());
double sidex = Math.abs(endPos.x - startPos.x);
double sidey = Math.abs(endPos.y - startPos.y);
int offset = 0;
Rectangle screenRect = new Rectangle((int) startPos.x-offset, (int)
startPos.y-offset,(int) sidex, (int) sidey);
Set<FeatureId> IDs = new HashSet<FeatureId>();
Filter filter = null;
AffineTransform screenToWorld = mapPane.getScreenToWorldTransform();
Rectangle2D worldRect =
screenToWorld.createTransformedShape(screenRect).getBounds2D();
ReferencedEnvelope bbox = new ReferencedEnvelope(
worldRect,
poifeatureSource.getSchema().getCoordinateReferenceSystem());
bbox = screenToWorld(poifeatureSource, startPos, endPos);
/*
* Create a Filter to select features that intersect with
* the bounding box
*/
filter = ff2.intersects(ff2.property(poigeometryAttributeName),
ff2.literal(bbox));
try
{
SimpleFeatureCollection selectedFeatures =
poifeatureSource.getFeatures(filter);
System.out.println(selectedFeatures.size());
SimpleFeatureIterator iter = selectedFeatures.features();
try
{
while (iter.hasNext())
{
SimpleFeature feature = iter.next();
IDs.add(feature.getIdentifier());
}
}
finally
{
iter.close();
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
return IDs;
}
Stack Trace:
start: DirectPosition2D[280.0, 246.0]
end: DirectPosition2D[392.0, 337.0]
java.lang.NullPointerException
at
org.geotools.data.shapefile.ShapefileFeatureSource.getReaderInternal(Shapefi
leFeatureSource.java:237)
at
org.geotools.data.shapefile.ShapefileFeatureStore.getReaderInternal(Shapefil
eFeatureStore.java:124)
at
org.geotools.data.store.ContentFeatureSource.getReader(ContentFeatureSource.
java:563)
at
org.geotools.data.store.ContentFeatureCollection.size(ContentFeatureCollecti
on.java:242)
at
com.aseg.archviewer.MapContainer.selectPOIs(MapContainer.java:1169)
at
com.aseg.archviewer.POIMouseAdaptor.onMouseReleased(POIMouseAdaptor.java:132
)
at
org.geotools.swing.event.DefaultMapMouseEventDispatcher.mouseReleased(Defaul
tMapMouseEventDispatcher.java:131)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown
Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown
Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown
Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown
Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. Consolidate legacy IT systems to a single system of record for IT
2. Standardize and globalize service processes across IT
3. Implement zero-touch automation to replace manual, redundant tasks
http://pubads.g.doubleclick.net/gampad/clk?id=51271111&iu=/4140/ostg.clktrk
_______________________________________________
GeoTools-GT2-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users