|
From: Alessandro F. <ale...@gm...> - 2011-03-21 16:36:52
|
Sorry to bring this back to life but I have come up against this issue
again, when running under threaded environment. Only happens using geotools
2.7.RC2
The weird thing is that the shapefile reading code works when running in the
main thread. When I have multiple threads reading different shapefiles, I
will receive the following error message:
ERROR 2011-03-21 11:16:28,250 [Thread-3] Test: Unable to find function
Length
java.lang.RuntimeException: Unable to find function Length
at
org.geotools.filter.FunctionFinder.findFunction(FunctionFinder.java:103)
at
org.geotools.filter.FunctionFinder.findFunction(FunctionFinder.java:69)
at
org.geotools.filter.FilterFactoryImpl.function(FilterFactoryImpl.java:469)
at
org.geotools.feature.AttributeTypeBuilder.lengthRestriction(AttributeTypeBuilder.java:624)
at
org.geotools.feature.AttributeTypeBuilder.buildType(AttributeTypeBuilder.java:455)
at
org.geotools.feature.AttributeTypeBuilder.buildDescriptor(AttributeTypeBuilder.java:516)
at
org.geotools.data.shapefile.ShapefileDataStore.readAttributes(ShapefileDataStore.java:811)
at
org.geotools.data.shapefile.ShapefileDataStore.getSchema(ShapefileDataStore.java:714)
at
org.geotools.data.shapefile.ShapefileDataStore.getSchema(ShapefileDataStore.java:708)
at
org.geotools.data.shapefile.ShapefileDataStore.getFeatureSource(ShapefileDataStore.java:1040)
at Test$geom_reader_thread.run(Test.java:101)
at java.lang.Thread.run(Thread.java:619)
Here is the test program: to run under single thread just run:
java -cp <jarfiles> Test false
to run under threaded environment run:
java -cp <jarfiles> Test true
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import org.geotools.data.DataStore;
import org.geotools.data.DataStoreFinder;
import org.geotools.data.FeatureSource;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
public class Test {
private boolean threaded = false;
private String[] testshpfiles = new String[]{
"/home/ferru001/COLLECTION-SHAPEFILES/cp_2008_01_collblock_3.shp",
"/home/ferru001/COLLECTION-SHAPEFILES/cp_2008_02_collblock_3.shp",
"/home/ferru001/COLLECTION-SHAPEFILES/cp_2008_04_collblock_3.shp",
"/home/ferru001/COLLECTION-SHAPEFILES/cp_2008_05_collblock_3.shp",
"/home/ferru001/COLLECTION-SHAPEFILES/cp_2008_06_collblock_3.shp",
"/home/ferru001/COLLECTION-SHAPEFILES/cp_2008_08_collblock_3.shp"
};
private static final Logger logger = Logger.getLogger(Test.class);
public static void main(String[] args) {
boolean threaded = Boolean.parseBoolean(args[0]);
logger.info("threaded=" + threaded);
new Test(threaded).runTest();
}
public Test(boolean threaded) {
this.threaded = threaded;
}
public void runTest() {
if (threaded) {
for (String testshpfile : testshpfiles) {
new Thread(new geom_reader_thread(testshpfile)).start();
}
}
else {
for (String testshpfile : testshpfiles) {
logger.info("reading "+testshpfile);
read_geom(testshpfile);
}
}
}
public void read_geom(String shpfile) {
try {
File shpfilef = new File(shpfile);
Map map = new HashMap();
map.put("url", shpfilef.toURI().toURL());
DataStore store = DataStoreFinder.getDataStore(map);
String typeName = store.getTypeNames()[0];
FeatureSource<SimpleFeatureType, SimpleFeature> featureSource =
store.getFeatureSource(typeName);
FeatureCollection<SimpleFeatureType, SimpleFeature> collection =
featureSource.getFeatures();
FeatureIterator<SimpleFeature> iterator = collection.features();
while (iterator.hasNext()) {
SimpleFeature feature = iterator.next();
String colblkst = (String) feature.getAttribute(1);
String colblkcou = (String) feature.getAttribute(2);
String colblk = (String) feature.getAttribute(3);
}
}
catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
}
class geom_reader_thread implements Runnable {
private String shpfile;
public geom_reader_thread(String shpfile) {
this.shpfile = shpfile;
}
public void run() {
logger.info("reading "+shpfile);
File shpfilef = new File(shpfile);
Map map = new HashMap();
try {
map.put("url", shpfilef.toURI().toURL());
DataStore store = DataStoreFinder.getDataStore(map);
String typeName = store.getTypeNames()[0];
FeatureSource<SimpleFeatureType, SimpleFeature>
featureSource = store.getFeatureSource(typeName);
FeatureCollection<SimpleFeatureType, SimpleFeature>
collection = featureSource.getFeatures();
FeatureIterator<SimpleFeature> iterator =
collection.features();
while (iterator.hasNext()) {
SimpleFeature feature = iterator.next();
String colblkst = (String) feature.getAttribute(1);
String colblkcou = (String) feature.getAttribute(2);
String colblk = (String) feature.getAttribute(3);
}
}
catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
}
}
}
On Sat, Mar 19, 2011 at 4:56 PM, Alessandro Ferrucci <
ale...@gm...> wrote:
> Andrea,
>
> In fact I've decided that it is undoubtedly easier to work with maven when
> using geotools.
>
> I will go back to using maven moving forward.
>
> Thanks for your assistance.
>
> Regards,
>
> Alessandro Ferrucci
>
>
> On Sat, Mar 19, 2011 at 3:48 AM, Andrea Aime <and...@ge...
> > wrote:
>
>> On Fri, Mar 18, 2011 at 11:31 PM, Alessandro Ferrucci
>> <ale...@gm...> wrote:
>>
>> > I've found lots of postings about people having this exact same issue
>> but
>> > they were all using maven plugin voodoo and creating these service
>> functions
>> > at build time... I am not using maven but pre-built bin jars downloaded
>> from
>>
>> Alessandro,
>> the only way to keep it simple is to use maven, what you're doing is
>> trying to
>> divine the list or required jars out of thin air, that's the real voodoo.
>>
>> If you need to read a shapefile the minimum set of jars you need, and
>> really
>> don't want to use maven to build, you'll still have to use maven, and the
>> gt2 sources, to get the list of required jars.
>>
>> Running mvn depency:list from the gt-shapefile module one gets:
>>
>> mvn dependency:list -o
>> [INFO]
>> NOTE: Maven is executing in offline mode. Any artifacts not already in
>> your local
>> repository will be inaccessible.
>>
>> [INFO] Scanning for projects...
>> [INFO] Searching repository for plugin with prefix: 'dependency'.
>> [INFO]
>> ------------------------------------------------------------------------
>> [INFO] Building Shapefile module
>> [INFO] task-segment: [dependency:list]
>> [INFO]
>> ------------------------------------------------------------------------
>> [INFO] [dependency:list {execution: default-cli}]
>> [INFO]
>> [INFO] The following files have been resolved:
>> [INFO] com.vividsolutions:jts:jar:1.11:compile
>> [INFO] commons-pool:commons-pool:jar:1.5.4:compile
>> [INFO] hsqldb:hsqldb:jar:1.8.0.7:test
>> [INFO] java3d:vecmath:jar:1.3.2:compile
>> [INFO] javax.media:jai_core:jar:1.1.3:provided
>> [INFO] jdom:jdom:jar:1.0:compile
>> [INFO] junit:junit:jar:4.4:test
>> [INFO] net.java.dev.jsr-275:jsr-275:jar:1.0-beta-2:compile
>> [INFO] org.geotools:gt-api:jar:2.8-SNAPSHOT:compile
>> [INFO] org.geotools:gt-data:jar:2.8-SNAPSHOT:compile
>> [INFO] org.geotools:gt-epsg-hsql:jar:2.8-SNAPSHOT:test
>> [INFO] org.geotools:gt-main:jar:2.8-SNAPSHOT:compile
>>
>> To run you'll need all the compile and provided ones, plugin a epsg db
>> plugin,
>> like gt-epsg-wkt or gt-epsg-hsql (but not both, see the documentation).
>>
>> Cheers
>> Andrea
>>
>>
>>
>> --
>> -------------------------------------------------------
>> Ing. Andrea Aime
>> GeoSolutions S.A.S.
>> Tech lead
>>
>> Via Poggio alle Viti 1187
>> 55054 Massarosa (LU)
>> Italy
>>
>> phone: +39 0584 962313
>> fax: +39 0584 962313
>> mob: +39 333 8128928
>>
>> http://www.geo-solutions.it
>> http://geo-solutions.blogspot.com/
>> http://www.youtube.com/user/GeoSolutionsIT
>> http://www.linkedin.com/in/andreaaime
>> http://twitter.com/geowolf
>>
>> -------------------------------------------------------
>>
>
>
>
> --
> Signed,
> Alessandro Ferrucci
>
--
Signed,
Alessandro Ferrucci
|