Review improvements DXF module.
-------------------------------
Key: GEOT-3800
URL: https://jira.codehaus.org/browse/GEOT-3800
Project: GeoTools
Issue Type: Improvement
Components: unsupported
Reporter: Roy Braam
Assignee: Roy Braam
Priority: Minor
Hello,
Many people have been asking about the DXF-module lately. I have been using it
for a quite long time in our company's internal project. For this purpose I
have made many customizations for the dxf-module. These include
- invertion of coordinates: eg. x in dxf becomes y in the geometries
- much better functioning text (with unicode support)
- support for UCS origo not in 0,0,0
- simpler process for reading the file and setting coordinate system
- support for closed polylines = polygons
- better support for ellipses
- block insertion points work better now
There's still plenty to do and the code is not the most clean, but my version
meets more or less our requirements all ready.
Here is some useful sample code. The key to everything is to use the automatic
style.
Creating the feature source:
File file = new File(filename);
DXFDataStoreFactory factory = new DXFDataStoreFactory();
Map map = new HashMap();
map.put(DXFDataStoreFactory.PARAM_SRS.key, CRS.decode("EPSG:xxxx"));
map.put(DXFDataStoreFactory.PARAM_URL.key, file.toURI().toURL());
store = factory.createDataStore(map);
featureSource = store.getFeatureSource("");
Automatically creating the style based on the dxf itself:
protected FeatureTypeStyle createLineStyle() {
org.opengis.filter.expression.Expression color;
color = new AttributeExpressionImpl("color");
Stroke stroke = styleFactory.createStroke(
color, new AttributeExpressionImpl("thickness"));
LineSymbolizer sym = styleFactory.createLineSymbolizer(stroke, null);
org.geotools.styling.Rule rule = styleFactory.createRule();
rule.setFilter(filterFactory.notEqual(new
AttributeExpressionImpl("visible"),
filterFactory.literal(0)));
rule.setElseFilter(true);
rule.symbolizers().add(sym);
return styleFactory.createFeatureTypeStyle(new
org.geotools.styling.Rule[]{rule});
}
protected FeatureTypeStyle createPolygonStyle() {
org.opengis.filter.expression.Expression color;
color = new AttributeExpressionImpl("color");
Stroke stroke = styleFactory.createStroke(color,
new AttributeExpressionImpl("thickness"));
PolygonSymbolizer sym = styleFactory.createPolygonSymbolizer(stroke,
null, null);
org.geotools.styling.Rule rule = styleFactory.createRule();
rule.setFilter(filterFactory.notEqual(new
AttributeExpressionImpl("visible"),
filterFactory.literal(0)));
rule.setElseFilter(true);
rule.symbolizers().add(sym);
return styleFactory.createFeatureTypeStyle(new
org.geotools.styling.Rule[]{rule});
}
protected FeatureTypeStyle createTextStyle() {
org.opengis.filter.expression.Expression color;
color = new AttributeExpressionImpl("color");
StyleBuilder styleBuilder = new StyleBuilder();
AnchorPoint anchor = new AnchorPoint();
anchor.setAnchorPointX(new AttributeExpressionImpl("align1"));
anchor.setAnchorPointY(new AttributeExpressionImpl("align2"));
Fill fill = styleFactory.createFill(color);
PointPlacementImpl labelPlacement = new
PointPlacementImpl(filterFactory);
labelPlacement.setRotation(filterFactory.multiply(filterFactory.literal(-1),
new AttributeExpressionImpl("rotation")));
labelPlacement.setAnchorPoint(anchor);
labelPlacement.setDisplacement(Displacement.DEFAULT);
Font font = styleBuilder.createFont(filterFactory.literal("SansSerif"),
filterFactory.literal(1), filterFactory.literal(1),
new AttributeExpressionImpl("height"));
TextSymbolizer sym = styleFactory.createTextSymbolizer(fill,
new Font[]{font}, null,
new AttributeExpressionImpl("text"), labelPlacement, null);
sym.setUnitOfMeasure(SI.METRE);
org.geotools.styling.Rule rule = styleFactory.createRule();
rule.setFilter(filterFactory.notEqual(new
AttributeExpressionImpl("visible"),
filterFactory.literal(0)));
rule.setElseFilter(true);
rule.symbolizers().add(sym);
return styleFactory.createFeatureTypeStyle(new
org.geotools.styling.Rule[]{rule});
}
protected Style createStyle() {
Style s = styleFactory.createStyle();
s.featureTypeStyles().add(createLineStyle());
s.featureTypeStyles().add(createPolygonStyle());
s.featureTypeStyles().add(createTextStyle());
return s;
}
The generated style handles font heights, colors, line widths etc.
You can download my changed version of the module (including the jar in target)
here:
http://www.sunela.eu/maku/gt-2.7-dxf-2011-08-17.zip
And the diff is here:
http://www.sunela.eu/maku/gt-2.7-dxf-2011-08-17.diff
Regards,
Markus
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system,
user administration capabilities and model configuration. Take
the hassle out of deploying and managing Subversion and the
tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel