Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 2.5-RC0
-
Fix Version/s: 2.7-M4
-
Component/s: jdbc-postgis plugin
-
Labels:None
Description
The addition of M Geometry types in Hashmap named "GEOM_TYPE_MAP" in PostgisDataStore.java may cause the wrong Geometry type to be used and the createSchema method to fail.
Example mapping:
GEOM_TYPE_MAP.put("POINT", Point.class);
GEOM_TYPE_MAP.put("POINTM", Point.class);
The Hashmap "GEOM_CLASS_MAPPINGS" attempts to create mappings in the reverse direction (from Class to String), but the two Strings share the same Class resulting in only one of the two mappings.
Depending on the order of the keySet returned from "GEOM_TYPE_MAP" the M Geometry type String may be mapped to the class.
The createSchema method calls getGeometrySQLTypeName method which uses this HashMap "GEOM_CLASS_MAPPINGS" and will cause this method to fail from the CONSTRAINT enforce_geotype when the wrong Geometry type String is returned.
This is a very annoying bug. I cannot create any Geometry in PostGis DB. I have to create shapefile and after import it to PostGreSQL.
I don't understand why you add M geometry ? JTS does not support it. So you cannot create a symmetric mapping between PostGIS and JTS.
I propose you 2 solutions :
- create the mapping GEOM_CLASS_MAPPINGS "by hand"
static {
GEOM_CLASS_MAPPINGS.put(Geometry.class, "GEOMETRY");
GEOM_CLASS_MAPPINGS.put(Point.class, "POINT");
GEOM_CLASS_MAPPINGS.put(LineString.class, "LINESTRING");
GEOM_CLASS_MAPPINGS.put(Polygon.class, "POLYGON");
GEOM_CLASS_MAPPINGS.put(MultiPoint.class, "MULTIPOINT");
GEOM_CLASS_MAPPINGS.put(MultiLineString.class, "MULTILINESTRING");
GEOM_CLASS_MAPPINGS.put(MultiPolygon.class, "MULTIPOLYGON");
GEOM_CLASS_MAPPINGS.put(GeometryCollection.class, "GEOMETRYCOLLECTION");
}
- or patch the code, to choose always the Geometry name without M
@line 179 in PostgisDataStore.java
static {
// init the inverse map
Set keys = GEOM_TYPE_MAP.keySet();
for (Iterator it = keys.iterator(); it.hasNext();) {
String name = (String) it.next();
Class geomClass = (Class) GEOM_TYPE_MAP.get(name);
/// Begin proposed patch
String existName = GEOM_CLASS_MAPPINGS.get(geomClass)
// we add the mapping if it does'nt exist or if the name is shorter (without M)
if(existName == null || existName.length() < name.length())
/// End proposed patch
GEOM_CLASS_MAPPINGS.put(geomClass, name);
}
}
Thanks for your work