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