Invoking Geoscript Class from another Java project or Command Line

85 views
Skip to first unread message

Prakash Viswanathan

unread,
Feb 27, 2012, 9:51:03 PM2/27/12
to GeoScript
Hello Geoscript Users,

I am trying to invoke a geoscript groovy project's class from inside
another java project (also tried invoking from command line) and I
keep getting this "could not find matching constructor" error, could
someone please tell me how to get past this error.

geoscript groovy project has a class called Plotter and is compiled
with all dependencies into geoscript-groovy.jar using gradle.

C:\Users\user\Desktop\lib\geoscript\libs>java -classpath .;geoscript-
groovy.jar;C:\sw\geoscript-groovy-0.95\lib\groovy-1.7.0.jar
com.company.project.ops.Plotter
Exception in thread "main" groovy.lang.GroovyRuntimeException: Could
not find matching constructor for:
org.geotools.data.directory.DirectoryDataStore(java.io.File,
org.geotools.da
ta.shapefile.ShapefileDataStoreFactory$ShpFileStoreFactory)
at
groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1484)
at
groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1400)
at
org.codehaus.groovy.runtime.callsite.MetaClassConstructorSite.callConstructor(MetaClassConstructorSite.java:
46)
at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:
52)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:
192)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:
204)
at geoscript.workspace.Directory.<init>(Directory.groovy:19)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at
org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:
77)
at org.codehaus.groovy.runtime.callsite.ConstructorSite
$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:
107)
at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:
52)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:
192)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:
200)
at geoscript.layer.Shapefile.create(Shapefile.groovy:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:
88)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite
$StaticMetaMethodSiteNoUnwrapNoCoerce.invoke(StaticMetaMethodSite.java:
148)
at
org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.callStatic(StaticMetaMethodSite.java:
99)
at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:
48)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:
167)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:
175)
at geoscript.layer.Shapefile.<init>(Shapefile.groovy:18)
at geoscript.layer.Shapefile.<init>(Shapefile.groovy:26)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at
org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:
77)
at org.codehaus.groovy.runtime.callsite.ConstructorSite
$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:
107)
at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:
52)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:
192)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:
200)
at com.company.project.ops.Plotter.createMap(Plotter.groovy:
37)

Thanks
Prakash

Jared Erickson

unread,
Feb 27, 2012, 10:59:22 PM2/27/12
to geos...@googlegroups.com
Hi Prakash!

Groovy stack traces are notoriously nasty, could you include the code snippet that is producing this error? Could you try upgrading to 0.97? The version you are using is a year old and I have fixed a lot bugs between then and now.

Thanks,
Jared

> --
> You received this message because you are subscribed to the GeoScript mailing list.
> To post to this group, send email to geos...@googlegroups.com
> To unsubscribe from this group, send email to geoscript+...@googlegroups.com
> Visit this group at http://groups.google.com/group/geoscript or see http://geoscript.org

Prakash Viswanathan

unread,
Feb 28, 2012, 9:35:22 AM2/28/12
to GeoScript
Hi Jared,

Please find below the class that i am using to draw a map, I got few
errors when i updated the libraries to 0.97,
I have errors at
geoscript.map.Map
PolygonSymbolizer and
PointSymbolizer

They were all used previously as shown below, I am aware the api was
under change, please let me know what is the work around for this.

class Plotter
{
static String sep = System.getProperty("file.separator")

static String createMap(String shapeFileName, String
outputFilePath, List<PlotterPoint> plotterPoints)
{
def map = new Map(width: 1024, height: 768) // BREAKS IN 0.97
def shp = new Shapefile(shapeFileName)
shp.style = new Style(new PolygonSymbolizer(fillColor:
"#0055BB",strokeOpacity: 0)) // BREAKS IN 0.97
map.bounds = shp.bounds
map.addLayer(shp)
def timestamp = new Date().getTime().toString()
createShapeFile(outputFilePath + sep + timestamp + ".shp",
plotterPoints)
shp = new Shapefile(outputFilePath + sep + timestamp + ".shp")
shp.style = new Style(new PointSymbolizer(shape:
"circle",fillColor: "#AABB00",size: 6,strokeColor:
"white",strokeWidth: 0.5)) // BREAKS IN 0.97
map.addLayer(shp)
File mapFile = new File(outputFilePath + sep + "world_" +
timestamp + ".png")
map.render(mapFile)
mapFile.getPath()
}

public static void main(String[] args)
{
def plotterPoints = []
plotterPoints << new PlotterPoint(latitude: 15.770771,
longitude: 75.999667)
plotterPoints << new PlotterPoint(latitude: 41.096458,
longitude: -97.22416)
plotterPoints << new PlotterPoint(latitude: 47.493034,
longitude: 2.785247)
createMap("\\\\networkpath\\all_countries.shp", "c:\\test",
plotterPoints)
}

private static void createShapeFile(String shpFileName,
List<PlotterPoint> plotterPoints)
{
try
{
DataStoreFactorySpi factory = new
ShapefileDataStoreFactory();
File file = new File(shpFileName);

java.util.Map<String,Serializable> map = new
HashMap<String,Serializable>();
map.put("url", file.toURL() );
map.put("create spatial index",Boolean.FALSE);

DataStore dataStore = factory.createNewDataStore(map);
FeatureType featureType = DataUtilities.createType( "my",
"geom:Point:srid=4326");
dataStore.createSchema( (SimpleFeatureType) featureType );
FeatureCollection featColl =
FeatureCollections.newCollection();

plotterPoints.each {point->
SimpleFeature feat =
createNewFeature(featureType,createPoint(point.getLatitude(),
point.getLongitude()))
if (feat!=null){
featColl.add(feat);
}
}

String[] typeNames = dataStore.getTypeNames();
String typeName = typeNames[0];
Transaction transaction = new
DefaultTransaction("Create");
FeatureStore<SimpleFeatureType, SimpleFeature>
featureStore;
featureStore = (FeatureStore<SimpleFeatureType,
SimpleFeature>) dataStore.getFeatureSource(typeName);
featureStore.setTransaction(transaction);
featureStore.addFeatures(featColl);
transaction.commit();
transaction.close();
}
catch (Exception e){
e.printStackTrace()
}
}

private static SimpleFeature createNewFeature(FeatureType
fType,Point createFromPoint)
{
SimpleFeature feature=null;
try
{
Point loc = new GeometryFactory().createPoint(new
Coordinate(createFromPoint.getX(),createFromPoint.getY()))
SimpleFeatureBuilder builder = new
SimpleFeatureBuilder((SimpleFeatureType) fType)
builder.set("geom", loc)
feature = builder.buildFeature(null)
} catch (Exception e){
e.printStackTrace()
}
return feature;
}

private static Point createPoint(double latitude, double
longitude)
{
GeometryFactory geometryFactory =
JTSFactoryFinder.getGeometryFactory(GeoTools.getDefaultHints())
geometryFactory.createPoint(new
Coordinate( longitude,latitude))
}
}

Thanks
Prakash

Prakash Viswanathan

unread,
Feb 28, 2012, 10:01:54 AM2/28/12
to GeoScript
Please ignore my last email, I changed the code a bit and it seems to
get me past the compilation errors, I will post an update if i am able
to call it from another java project and/or command line in a bit.

Here are the changes i made to get past the compilation error after
updating to 0.97,
Map is now in this package
import geoscript.render.Map

Instead of PolygonSymbolizer and Point Symbolizer i tried this
shp.style = new Fill("#00FFEE") + new Stroke("#112233", 0.1) and
shp.style = new Shape("#AABB00",6, "circle")

Thanks
Prakash

On Feb 28, 8:35 am, Prakash Viswanathan <rushtoprak...@gmail.com>
wrote:
> ...
>
> read more »

Prakash Viswanathan

unread,
Feb 28, 2012, 11:54:32 AM2/28/12
to GeoScript
Here is a sample class in my java project

public class GeoScriptTest
{
    public static void main(String[] args)
    {
        List<PlotterPoint> plotterPoints = new
ArrayList<PlotterPoint>();
        PlotterPoint p = new PlotterPoint();
        p.setLatitude(15.770771);
        p.setLongitude(75.999667);
        plotterPoints.add(p);
        p = new PlotterPoint();
        p.setLatitude(41.096458);
        p.setLongitude(-97.22416);
        plotterPoints.add(p);

        Plotter.createMap("\\\\networkdir\\all_countries.shp", "c:\
\test", plotterPoints);
    }
}

I get this exception now with 0.97 libraries, Please tell me how to
get past this NoSuchMethodError

Exception in thread "main"
org.codehaus.groovy.runtime.InvokerInvocationException:
java.lang.NoSuchMethodError:
org.geotools.util.Utilities.ensureNonNull(Ljava/lang/String;Ljava/lang/
Object;)V
at
org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:
79)
at org.codehaus.groovy.runtime.callsite.ConstructorSite
$NoParamSite.callConstructor(ConstructorSite.java:120)
at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:
52)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:
190)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:
198)
at com.company.project.ops.Plotter.createMap(Plotter.groovy:35)
at com.company.project.GeoScriptTest.main(GeoScriptTest.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:
120)
Caused by: java.lang.NoSuchMethodError:
org.geotools.util.Utilities.ensureNonNull(Ljava/lang/String;Ljava/lang/
Object;)V
at
org.geotools.coverage.processing.CoverageProcessor.getOperation(CoverageProcessor.java:
450)
at
org.geotools.renderer.lite.StreamingRenderer.<clinit>(StreamingRenderer.java:
216)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at geoscript.render.Map.class$(Map.groovy)
at geoscript.render.Map.$get$$class$org$geotools$renderer$lite
$StreamingRenderer(Map.groovy)
at geoscript.render.Map.<init>(Map.groovy:94)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:
39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:
27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at
org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:
77)
... 11 more

Thanks
Prakash

On Feb 28, 9:01 am, Prakash Viswanathan <rushtoprak...@gmail.com>
> ...
>
> read more »

Prakash Viswanathan

unread,
Feb 28, 2012, 12:08:33 PM2/28/12
to GeoScript
Works well from command line, something is not right when run from
another Scala/Java project
java -classpath .;geoscript_groovy.jar;C:\sw\geoscript-groovy-0.97\lib
\groovy-1.7.10.jar com.navteq.lcs.ops.Plotter

On Feb 28, 10:54 am, Prakash Viswanathan <rushtoprak...@gmail.com>
wrote:
> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(C allSiteArray.java:
> 52)
>         at
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(Abstr actCallSite.java:
> 190)
>         at
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(Abstr actCallSite.java:
> ...
>
> read more »

Prakash Viswanathan

unread,
Feb 28, 2012, 5:23:43 PM2/28/12
to GeoScript
correction, it works well from inside another java project but when
including everything inside a web project which also has some scala
code, i keep getting the initial error
Exception in thread "main" groovy.lang.GroovyRuntimeException: Could
not find matching constructor for:
org.geotools.data.directory.DirectoryDataStore(java.io.File,
org.geotools.da
ta.shapefile.ShapefileDataStoreFactory$ShpFileStoreFactory)

i am lost, don't know how to get past this.

On Feb 28, 11:08 am, Prakash Viswanathan <rushtoprak...@gmail.com>
> ...
>
> read more »

Justin Deoliveira

unread,
Feb 28, 2012, 6:54:43 PM2/28/12
to geos...@googlegroups.com
Looks to me like a mismatch of the underlying geotools libraries. Do you have multiple copies of them on the classpath? Or are you possibly using different ones than those that are shipping with geoscript-groovy?

> ...
>
> read more »

--
You received this message because you are subscribed to the GeoScript mailing list.
To post to this group, send email to geos...@googlegroups.com
To unsubscribe from this group, send email to geoscript+...@googlegroups.com



--
Justin Deoliveira
Enterprise support for open source geospatial.

Prakash Viswanathan

unread,
Feb 29, 2012, 11:10:16 AM2/29/12
to GeoScript
Thanks Justin, I think i mixed up libraries some how. I cleaned up my
workspace and added the 0.97 jars again.

It works fine from inside web app too.
> ...
>
> read more »
Reply all
Reply to author
Forward
0 new messages