Hi all,
I'm still confused with FIDs. My problem is no more with inserting (thanks to
Andrea) but with retrieving. I have severals kind of filter which are working
well, except from the FidFilter.
With this filter, it's very strange: as soon as my debuger passes through
col.size() or col.features() calls, I can see two different requests in the
geoserver logs:
The first request seems ok: fid parameter is set to 1000043
/////////////////////////////////
9818382 [INFO] org.vfny.geoserver.servlets.AbstractService - handling request:
Request: null
output format:GML2
max features:2147483647
version:
queries:
Query []
feature type: esig:esig_points
filter: [ esig_points.1000043 ]
[properties: ALL ]
But the second one is wrong: no more filter!
/////////////////////////////////
9818493 [INFO] org.vfny.geoserver.servlets.AbstractService - handling request:
Request: null
output format:GML2
max features:2147483647
version:
queries:
Query []
feature type: esig:esig_points
[properties: ALL ]
I don't understand why a second request is occuring. Since the wrong request
(without any filter) is the second one, there's always some features returned,
whatever the FID is. :(
If I replace the filterFactory.createFidFilter() call by another filter (such
my private method getFilterByUserId(), see below), it works correctly (ie. just
one request is sent, with the appropriate filter).
And, if I run my test program without breakpoint I have an exception:
Stopping
org.geotools.xml.gml.GMLComplexTypes$AbstractFeatureType.stream(GMLComplexTypes.java:4312)
org.geotools.xml.gml.GMLComplexTypes$AbstractFeatureType.getValue(GMLComplexTypes.java:4177)
org.geotools.xml.handlers.xsi.ComplexTypeHandler$DefaultComplexType.getValue(ComplexTypeHandler.java:1072)
org.geotools.xml.handlers.ComplexElementHandler.endElement(ComplexElementHandler.java:185)
org.geotools.xml.XMLSAXHandler.endElement(XMLSAXHandler.java:264)
org.apache.xerces.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:579)
org.apache.xerces.impl.XMLNamespaceBinder.handleEndElement(XMLNamespaceBinder.java:897)
org.apache.xerces.impl.XMLNamespaceBinder.endElement(XMLNamespaceBinder.java:643)
org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(XMLDTDValidator.java:1972)
org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(XMLDTDValidator.java:878)
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.handleEndElement(XMLDocumentFragmentScannerImpl.java:1144)
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:987)
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1445)
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:333)
org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:524)
org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:580)
org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:152)
org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1169)
javax.xml.parsers.SAXParser.parse(Unknown Source)
javax.xml.parsers.SAXParser.parse(Unknown Source)
org.geotools.xml.DocumentFactory.getInstance(DocumentFactory.java:139)
org.geotools.data.wfs.WFSFeatureReader.run(WFSFeatureReader.java:125)
But if I run my test program "slowly" (ie. debug with breakpoints), this
exception isn't raised anymore! Fantastic!
What's wrong with filterFactory.createFidFilter()? The method is marked as
obsolete, what would be the new/good approach?
Here is the relevant part from my code:
////////////////////////////////////////////////////////
public Feature getFeatureByFID(int fid) throws IOException,
InexistentFeatureException {
FeatureCollection col =
getFeatureStore().getFeatures(addFilterByLayerId(filterFactory.createFidFilter(featureTypeNameWithoutNS
+ "." + fid)));
logger.info(col.size() + " feature(s) are retrieved.");
FeatureIterator iter = col.features();
try {
if (iter.hasNext()) {
return iter.next();
} else {
throw new InexistentFeatureException("Unable to find a feature
whose FID is " + featureTypeNameWithoutNS + "." + fid);
}
} finally {
iter.close();
}
}
public FeatureCollection getFeaturesByUserId(String userId) throws
IOException {
return
getFeatureStore().getFeatures(addFilterByLayerId(getFilterByUserId(userId)));
}
public FeatureCollection getFeaturesWithinRect(Coordinate c1, Coordinate
c2) throws IOException {
return
getFeatureStore().getFeatures(addFilterByLayerId(getFilterWithinRect(c1, c2)));
}
public FeatureCollection getFeaturesWithinCircle(Coordinate center, long
radius) throws IOException {
return
getFeatureStore().getFeatures(addFilterByLayerId(getFilterWithinCircle(center,
radius)));
}
//
/////////////////////////////////////////////////////////////////////////////////
// Private methods for getting filters
//
/////////////////////////////////////////////////////////////////////////////////
private Filter addFilterByLayerId(Filter filter) throws IOException {
Filter newFilter = filterFactory.and(filter, getFilterByLayerId());
return newFilter;
}
private Filter getFilterByLayerId() throws IOException {
CompareFilter layerFilter =
filterFactory.createCompareFilter(CompareFilter.COMPARE_EQUALS);
layerFilter.addLeftValue(filterFactory.createAttributeExpression(getFeatureType(),
"layerid"));
layerFilter.addRightValue(filterFactory.createLiteralExpression(this.id));
return layerFilter;
}
private Filter getFilterByUserId(String userId) throws IOException {
CompareFilter layerFilter =
filterFactory.createCompareFilter(CompareFilter.COMPARE_EQUALS);
layerFilter.addLeftValue(filterFactory.createAttributeExpression(getFeatureType(),
"userid"));
layerFilter.addRightValue(filterFactory.createLiteralExpression(userId));
return layerFilter;
}
private Filter getFilterWithinRect(Coordinate c1, Coordinate c2) throws
IOException {
GeometryFilter geomFilter =
filterFactory.createGeometryFilter(AbstractFilter.GEOMETRY_BBOX);
geomFilter.addLeftGeometry(filterFactory.createBBoxExpression(new
Envelope(c1, c2)));
geomFilter.addRightGeometry(filterFactory.createAttributeExpression(getFeatureType().getDefaultGeometry()
.getName()));
return geomFilter;
}
private Filter getFilterWithinCircle(Coordinate center, long radius) throws
IOException {
GeometryDistanceFilter geomFilter =
filterFactory.createGeometryDistanceFilter(AbstractFilter.GEOMETRY_DWITHIN);
geomFilter.setDistance(radius);
Point p = geomFactory.createPoint(center);
p.setSRID(srsId);
p.setUserData(srsId); // bizarre si userData est null le filtre lève
une exception!
geomFilter.addLeftGeometry(filterFactory.createLiteralExpression(p));
geomFilter.addRightGeometry(filterFactory.createAttributeExpression(getFeatureType().getDefaultGeometry()
.getName()));
return geomFilter;
}
Thanks a lot for your precious help,
Regards,
Vincent.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users