Michael Fröhler created GEOT-4003:
-------------------------------------
Summary: Point Shapes - Invalid Point Geometrie returned at
ShapeType.NULL
Key: GEOT-4003
URL: https://jira.codehaus.org/browse/GEOT-4003
Project: GeoTools
Issue Type: Bug
Components: shapefile plugin
Affects Versions: 2.7.4
Reporter: Michael Fröhler
Assignee: Andrea Aime
Its better to return an empty geometry for a null as an invalid point with NaN
in all coordinates. This could lead to strange effects in applications working
with the returned Geometries.
Fix can be the following:
At PointHandler:
#############
private Object createNull() {
//Returns empty geometry of type Point
return geometryFactory.createPoint((Coordinate)null);
}
public void write(ByteBuffer buffer, Object geometry) {
if(geometry==null || ((Geometry)geometry).isEmpty()){
//If geometry is empty write zero coordinates - no problem as
shapetype should be null in that case
buffer.putDouble(0d);
buffer.putDouble(0d);
return;
}
Coordinate c = ((Point) geometry).getCoordinate();
buffer.putDouble(c.x);
buffer.putDouble(c.y);
if (shapeType == ShapeType.POINTZ) {
if (Double.isNaN(c.z)) { // nan means not defined
buffer.putDouble(0.0);
} else {
buffer.putDouble(c.z);
}
}
if ((shapeType == ShapeType.POINTZ) || (shapeType == ShapeType.POINTM))
{
buffer.putDouble(-10E40); // M
}
}
#############
At ShapefileWriter:
##################
public void writeGeometry(Geometry g) throws IOException {
if (shapeBuffer == null)
throw new IOException("Must write headers first");
lp = shapeBuffer.position();
int length = handler.getLength(g);
// must allocate enough for shape + header (2 ints)
checkShapeBuffer(length + 8);
length /= 2;
shapeBuffer.order(ByteOrder.BIG_ENDIAN);
shapeBuffer.putInt(++cnt);
shapeBuffer.putInt(length);
shapeBuffer.order(ByteOrder.LITTLE_ENDIAN);
if(g==null || g.isEmpty()){
//Set shapetype to null if geometry is empty or null
shapeBuffer.putInt(ShapeType.NULL.id);
}else{
shapeBuffer.putInt(type.id);
}
handler.write(shapeBuffer, g);
assert (length * 2 == (shapeBuffer.position() - lp) - 8);
lp = shapeBuffer.position();
// write to the shx
indexBuffer.putInt(offset);
indexBuffer.putInt(length);
offset += length + 4;
drain();
assert (shapeBuffer.position() == 0);
}
###############
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://jira.codehaus.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create
new or port existing apps to sell to consumers worldwide. Explore the
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel