|
From: Alessandro F. <ale...@gm...> - 2011-03-19 20:54:29
|
Michael, thanks for taking the time of building your own 'old school'
sandbox, was very nice of you :)
I have actually decided to rebuild my entire sandbox and set class paths
again.
I got it to work but I needed more jar files than you've described below:
gt-data-2.7-RC2.jar
gt-metadata-2.7-RC2.jar
gt-referencing-2.7-RC2.jar
jsr-275-1.0-beta-2.jar
gt-api-2.7-RC2.jar
gt-main-2.7-RC2.jar
gt-opengis-2.7-RC2.jar
gt-shapefile-2.7-RC2.jar
jts-1.11.jar
Thanks again.
On Sat, Mar 19, 2011 at 3:25 AM, Michael Bedward
<mic...@gm...>wrote:
> Hi Alessandro,
>
> I just tried your "old school" code in a plain vanilla java app with
> the following jars attached:
>
> gt-api
> gt-data
> gt-main
> gt-shapefile
> gt-opengis
>
> All taken from the 2.7-RC2 distribution. The app runs without error on
> my system (Java 1.6, OSX). The code I used is below. I'm guessing
> that it's a classpath issue at your end, unless someone else is able
> to replicate the problem.
>
> Michael
>
> package mxb.geotools.testapp;
>
> import java.io.File;
> import java.util.HashMap;
> import java.util.List;
> import java.util.Map;
> import java.util.logging.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;
> import org.opengis.feature.type.AttributeDescriptor;
>
> public class Foo {
> private static final Logger logger =
> Logger.getLogger(Foo.class.getName());
>
> public static void main(String[] args) throws Exception {
> Foo foo = new Foo();
> foo.runTest(new
> File("/Users/michael/coding/geotools/data/refractions/bc_border.shp"));
> }
>
> private void runTest(File shpfile) throws Exception {
> Map map = new HashMap();
> map.put("url", shpfile.toURI().toURL());
> DataStore store = DataStoreFinder.getDataStore(map);
> String[] typeNames = store.getTypeNames();
> String typeName = typeNames[0];
> logger.info("typeName: " + typeName);
> FeatureSource<SimpleFeatureType, SimpleFeature> featureSource
> = store.getFeatureSource(typeName);
> SimpleFeatureType ft = featureSource.getSchema();
> Map<String, Integer> attributemap = new HashMap<String, Integer>();
> List<AttributeDescriptor> attrdescripts =
> ft.getAttributeDescriptors();
> for (int x = 0; x < attrdescripts.size(); x++) {
> attributemap.put(attrdescripts.get(x).getLocalName(), x);
> }
>
> FeatureCollection<SimpleFeatureType, SimpleFeature> collection
> = featureSource.getFeatures();
> FeatureIterator<SimpleFeature> iterator = collection.features();
> int n = 0;
> try {
> // dumb code just for testing :)
> while (iterator.hasNext()) {
> iterator.next();
> n++ ;
> }
> } finally {
> iterator.close();
> }
> System.out.println("count = " + n);
>
> }
> }
>
>
> On 19 March 2011 09:31, Alessandro Ferrucci
> <ale...@gm...> wrote:
> > Testing pre-built 2.7.RC2 binaries to compile simple shapefile reading
> > program.
> >
> > Using 2.7.RC2 I get
> >
> > Exception in thread "Thread-5" Exception in thread "Thread-2"
> > 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 geom_reader.run(geom_reader.java:57)
> > at java.lang.Thread.run(Thread.java:619)
> >
> > If I swap out 2.7.RC2 geotools with 2.6.5 geotools it works fine.
> >
> > 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
> >
> >
> http://sourceforge.net/projects/geotools/files/GeoTools%202.7%20Releases/2.7-RC2/
> >
> >
> > and a simple.sh file to invoke java, keepin' it old school.
> >
> > I unjarred the gt-main and did find a lot of SPI files, with many
> functions
> > inside
> >
> > grep -r "Length" *
> > org.opengis.filter.expression.Function:org.geotools.filter.LengthFunction
> >
> org.opengis.filter.expression.Function:org.geotools.filter.function.FilterFunction_geomLength
> >
> org.opengis.filter.expression.Function:org.geotools.filter.function.FilterFunction_strLength
> >
> > The following are the jars I'm including in classpath:
> >
> > gt-api-2.7-RC2.jar
> > gt-main-2.7-RC2.jar
> > gt-opengis-2.7-RC2.jar
> > gt-shapefile-2.7-RC2.jar
> > jts-1.11.jar
> > gt-data-2.7-RC2.jar
> > gt-metadata-2.7-RC2.jar
> > gt-referencing-2.7-RC2.jar
> > jsr-275-1.0-beta-2.jar
> >
> >
> > code is straight forward:
> >
> > Map map = new HashMap();
> > map.put("url", shpfile.toURI().toURL());
> > DataStore store = DataStoreFinder.getDataStore(map);
> > String[] typeNames = store.getTypeNames();
> > String typeName = typeNames[0];
> > logger.info("typeName: " + typeName);
> > FeatureSource<SimpleFeatureType, SimpleFeature>
> > featureSource = store.getFeatureSource(typeName);
> > SimpleFeatureType ft = featureSource.getSchema();
> > Map<String, Integer> attributemap = new
> HashMap<String,
> > Integer>();
> > List<AttributeDescriptor> attrdescripts =
> > ft.getAttributeDescriptors();
> > for (int x = 0; x < attrdescripts.size(); x++) {
> >
> > attributemap.put(attrdescripts.get(x).getLocalName(), x);
> > }
> > FeatureCollection<SimpleFeatureType, SimpleFeature>
> > collection = featureSource.getFeatures();
> > FeatureIterator<SimpleFeature> iterator =
> > collection.features();
> > while (iterator.hasNext()) {
> > }
> >
> >
> > Any ideas?
> >
> > Thank you,
> > --
> > Signed,
> > Alessandro Ferrucci
> >
> >
> ------------------------------------------------------------------------------
> > Colocation vs. Managed Hosting
> > A question and answer guide to determining the best fit
> > for your organization - today and in the future.
> > http://p.sf.net/sfu/internap-sfd2d
> > _______________________________________________
> > Geotools-gt2-users mailing list
> > Geo...@li...
> > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
> >
> >
>
--
Signed,
Alessandro Ferrucci
|