1717 * You should have received a copy of the GNU General Public License
1818 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1919 */
20- package org .geotools . data . neo4j ;
20+ package org .neo4j . spatial . cli . tools ;
2121
2222import static java .awt .RenderingHints .KEY_ANTIALIASING ;
2323import static java .awt .RenderingHints .KEY_TEXT_ANTIALIASING ;
2828import java .awt .image .BufferedImage ;
2929import java .io .File ;
3030import java .io .IOException ;
31- import java .util .logging .Level ;
3231import java .util .logging .Logger ;
3332import javax .imageio .ImageIO ;
3433import org .geotools .api .data .DataStore ;
3534import org .geotools .api .data .SimpleFeatureStore ;
3635import org .geotools .api .feature .simple .SimpleFeature ;
3736import org .geotools .api .feature .simple .SimpleFeatureType ;
38- import org .geotools .api .feature .type .FeatureType ;
39- import org .geotools .api .filter .FilterFactory ;
40- import org .geotools .api .style .FeatureTypeStyle ;
41- import org .geotools .api .style .Fill ;
42- import org .geotools .api .style .Graphic ;
43- import org .geotools .api .style .LineSymbolizer ;
44- import org .geotools .api .style .Mark ;
45- import org .geotools .api .style .PointSymbolizer ;
46- import org .geotools .api .style .PolygonSymbolizer ;
47- import org .geotools .api .style .Rule ;
48- import org .geotools .api .style .Stroke ;
4937import org .geotools .api .style .Style ;
5038import org .geotools .api .style .StyleFactory ;
5139import org .geotools .data .DefaultTransaction ;
5240import org .geotools .factory .CommonFactoryFinder ;
5341import org .geotools .feature .FeatureCollection ;
54- import org .geotools .filter .text .cql2 .CQLException ;
55- import org .geotools .filter .text .ecql .ECQL ;
5642import org .geotools .geometry .jts .ReferencedEnvelope ;
5743import org .geotools .map .FeatureLayer ;
5844import org .geotools .map .MapContent ;
5945import org .geotools .renderer .lite .StreamingRenderer ;
6046import org .geotools .xml .styling .SLDParser ;
61- import org .locationtech .jts .geom .LineString ;
62- import org .locationtech .jts .geom .LinearRing ;
63- import org .locationtech .jts .geom .MultiLineString ;
64- import org .locationtech .jts .geom .MultiPoint ;
65- import org .locationtech .jts .geom .MultiPolygon ;
66- import org .locationtech .jts .geom .Point ;
67- import org .locationtech .jts .geom .Polygon ;
6847import org .neo4j .driver .AuthTokens ;
6948import org .neo4j .driver .Driver ;
7049import org .neo4j .driver .GraphDatabase ;
71- import org .neo4j .gis .spatial .SpatialTopologyUtils ;
50+ import org .neo4j .spatial .geotools .common .utilities .GeotoolsUtils ;
51+ import org .neo4j .spatial .geotools .common .utilities .RenderingUtils ;
52+ import org .neo4j .spatial .geotools .plugin .Neo4jSpatialDataStore ;
7253
7354public class StyledImageExporter {
7455
@@ -81,7 +62,6 @@ public class StyledImageExporter {
8162Rectangle displaySize =new Rectangle (400 ,300 );
8263private String []styleFiles ;
8364static final StyleFactory styleFactory =CommonFactoryFinder .getStyleFactory (null );
84- static final FilterFactory filterFactory =CommonFactoryFinder .getFilterFactory (null );
8565
8666public StyledImageExporter (Driver driver ,String database ) {
8767this .driver =driver ;
@@ -220,7 +200,7 @@ public void saveLayerImage(String[] layerNames, String sldFile, File imagefile,
220200}
221201
222202if (featureStyle ==null ) {
223- featureStyle =createStyleFromGeometry (featureSource .getSchema (),Color .BLUE ,
203+ featureStyle =RenderingUtils . createStyleFromGeometry (featureSource .getSchema (),Color .BLUE ,
224204Color .CYAN );
225205LOGGER .info ("Created style from geometry '" +
226206featureSource .getSchema ().getGeometryDescriptor ()
@@ -254,7 +234,7 @@ private static Style getStyleFromSLDFile(String sldFile) {
254234
255235private void saveMapContentToImageFile (MapContent mapContent ,File imagefile ,ReferencedEnvelope bounds )
256236throws IOException {
257- bounds =SpatialTopologyUtils .adjustBounds (bounds ,1.0 /zoom ,offset );
237+ bounds =GeotoolsUtils .adjustBounds (bounds ,1.0 /zoom ,offset );
258238
259239if (displaySize ==null ) {
260240displaySize =new Rectangle (0 ,0 ,800 ,600 );
@@ -291,151 +271,6 @@ private static Style createStyleFromSLD(String sldFile) {
291271return null ;
292272}
293273
294- public static Style createDefaultStyle (Color strokeColor ,Color fillColor ) {
295- return createStyleFromGeometry (null ,strokeColor ,fillColor );
296- }
297-
298- /**
299- * Here is a programmatic alternative to using JSimpleStyleDialog to
300- * get a Style. These methods works out what sort of feature geometry
301- * we have in the shapefile and then delegates to an appropriate style
302- * creating method.
303- * <a href="https://docs.geotools.org/stable/userguide/examples/stylefunctionlab.html">stylefunctionlab</a>
304- */
305- // TODO: Consider adding support for attribute based color schemes like in
306- public static Style createStyleFromGeometry (FeatureType schema ,Color strokeColor ,Color fillColor ) {
307- if (schema !=null ) {
308- Class <?>geomType =schema .getGeometryDescriptor ().getType ().getBinding ();
309- if (Polygon .class .isAssignableFrom (geomType )
310- ||MultiPolygon .class .isAssignableFrom (geomType )) {
311- return createPolygonStyle (strokeColor ,fillColor );
312- }
313- if (LineString .class .isAssignableFrom (geomType )
314- ||LinearRing .class .isAssignableFrom (geomType )
315- ||MultiLineString .class .isAssignableFrom (geomType )) {
316- return createLineStyle (strokeColor );
317- }
318- if (Point .class .isAssignableFrom (geomType )
319- ||MultiPoint .class .isAssignableFrom (geomType )) {
320- return createPointStyle (strokeColor ,fillColor );
321- }
322- }
323-
324- Style style =styleFactory .createStyle ();
325- style .featureTypeStyles ().addAll (createPolygonStyle (strokeColor ,fillColor ).featureTypeStyles ());
326- style .featureTypeStyles ().addAll (createLineStyle (strokeColor ).featureTypeStyles ());
327- style .featureTypeStyles ().addAll (createPointStyle (strokeColor ,fillColor ).featureTypeStyles ());
328- return style ;
329- }
330-
331- /**
332- * Create a Style to draw polygon features
333- */
334- public static Style createPolygonStyle (Color strokeColor ,Color fillColor ) {
335- return createPolygonStyle (strokeColor ,fillColor ,0.5 ,0.5 ,1 );
336- }
337-
338- /**
339- * Create a Style to draw polygon features
340- */
341- public static Style createPolygonStyle (Color strokeColor ,Color fillColor ,double stokeGamma ,double fillGamma ,
342- int strokeWidth ) {
343- // create a partially opaque outline stroke
344- Stroke stroke =styleFactory .createStroke (
345- filterFactory .literal (strokeColor ),
346- filterFactory .literal (strokeWidth ),
347- filterFactory .literal (stokeGamma ));
348-
349- // create a partial opaque fill
350- Fill fill =styleFactory .createFill (
351- filterFactory .literal (fillColor ),
352- filterFactory .literal (fillGamma ));
353-
354- /*
355- * Setting the geometryPropertyName arg to null signals that we want to
356- * draw the default geomettry of features
357- */
358- PolygonSymbolizer sym =styleFactory .createPolygonSymbolizer (stroke ,fill ,null );
359-
360- Rule rule =styleFactory .createRule ();
361- rule .symbolizers ().add (sym );
362- try {
363- rule .setFilter (ECQL .toFilter ("geometryType(the_geom)='Polygon' or geometryType(the_geom)='MultiPoligon'" ));
364- }catch (CQLException e ) {
365- LOGGER .log (Level .WARNING ,"" ,e );
366- }
367-
368- FeatureTypeStyle fts =styleFactory .createFeatureTypeStyle (rule );
369- Style style =styleFactory .createStyle ();
370- style .featureTypeStyles ().add (fts );
371-
372- return style ;
373- }
374-
375- /**
376- * Create a Style to draw line features
377- */
378- private static Style createLineStyle (Color strokeColor ) {
379- Stroke stroke =styleFactory .createStroke (
380- filterFactory .literal (strokeColor ),
381- filterFactory .literal (1 ));
382-
383- /*
384- * Setting the geometryPropertyName arg to null signals that we want to
385- * draw the default geomettry of features
386- */
387- LineSymbolizer sym =styleFactory .createLineSymbolizer (stroke ,null );
388-
389- Rule rule =styleFactory .createRule ();
390- rule .symbolizers ().add (sym );
391- try {
392- rule .setFilter (ECQL .toFilter (
393- "geometryType(the_geom)='LineString' or geometryType(the_geom)='LinearRing' or geometryType(the_geom)='MultiLineString'" ));
394- }catch (CQLException e ) {
395- LOGGER .log (Level .WARNING ,"" ,e );
396- }
397-
398- FeatureTypeStyle fts =styleFactory .createFeatureTypeStyle (rule );
399- Style style =styleFactory .createStyle ();
400- style .featureTypeStyles ().add (fts );
401-
402- return style ;
403- }
404-
405- /**
406- * Create a Style to draw point features as circles with blue outlines
407- * and cyan fill
408- */
409- private static Style createPointStyle (Color strokeColor ,Color fillColor ) {
410- Mark mark =styleFactory .getCircleMark ();
411- mark .setStroke (styleFactory .createStroke (filterFactory .literal (strokeColor ),filterFactory .literal (2 )));
412- mark .setFill (styleFactory .createFill (filterFactory .literal (fillColor )));
413-
414- Graphic gr =styleFactory .createDefaultGraphic ();
415- gr .graphicalSymbols ().clear ();
416- gr .graphicalSymbols ().add (mark );
417- gr .setSize (filterFactory .literal (5 ));
418-
419- /*
420- * Setting the geometryPropertyName arg to null signals that we want to
421- * draw the default geomettry of features
422- */
423- PointSymbolizer sym =styleFactory .createPointSymbolizer (gr ,null );
424-
425- Rule rule =styleFactory .createRule ();
426- rule .symbolizers ().add (sym );
427- try {
428- rule .setFilter (ECQL .toFilter ("geometryType(the_geom)='Point' or geometryType(the_geom)='MultiPoint'" ));
429- }catch (CQLException e ) {
430- LOGGER .log (Level .WARNING ,"" ,e );
431- }
432-
433- FeatureTypeStyle fts =styleFactory .createFeatureTypeStyle (rule );
434- Style style =styleFactory .createStyle ();
435- style .featureTypeStyles ().add (fts );
436-
437- return style ;
438- }
439274
440275public static void main (String []args )throws IOException {
441276if (args .length <6 ) {