GeoTools
  1. GeoTools
  2. GEOT-2066

PostgisDataStore 'M' Geometry Type Mapping

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major 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.

        Activity

        Hide
        Gilles Vuidel added a comment -
        This bug is also present in 2.5.2.

        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
        Show
        Gilles Vuidel added a comment - This bug is also present in 2.5.2. 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
        Hide
        Miles Jordan added a comment -
        It would be great if the M geometries could be removed from the class mappings until they are supported properly. This really is making things difficult!
        Show
        Miles Jordan added a comment - It would be great if the M geometries could be removed from the class mappings until they are supported properly. This really is making things difficult!
        Hide
        Matt Blanchette added a comment -
        In 2.6 and the 2.7 trunk,
        the PostGISDialect class (in jdbc-postgis) has a mapping named CLASS_TO_TYPE_MAP that matches Gilles first solution

        The PostgisDataStore class has also added curve geometry types in 2.6 that present the same problem as the M types
        Show
        Matt Blanchette added a comment - In 2.6 and the 2.7 trunk, the PostGISDialect class (in jdbc-postgis) has a mapping named CLASS_TO_TYPE_MAP that matches Gilles first solution The PostgisDataStore class has also added curve geometry types in 2.6 that present the same problem as the M types
        Hide
        Justin Deoliveira added a comment -
        This is fixed in the new postgis datastore.
        Show
        Justin Deoliveira added a comment - This is fixed in the new postgis datastore.
        Hide
        Andrea Aime added a comment -
        Mass closing all issues in resolved state that have not been reopened nor commented over in the last month
        Show
        Andrea Aime added a comment - Mass closing all issues in resolved state that have not been reopened nor commented over in the last month

          People

          • Assignee:
            Justin Deoliveira
            Reporter:
            Matt Blanchette
          • Votes:
            6 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: