Changeset: 3360b0e53c0c for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/3360b0e53c0c
Added Files:
geom/monetdb5/cleanup.md
geom/monetdb5/geod.c
geom/monetdb5/geod.h
geom/sql/spatial_ref_sys.sql
Modified Files:
geom/monetdb5/CMakeLists.txt
geom/monetdb5/geom.c
geom/monetdb5/geom.h
geom/monetdb5/geomBulk.c
geom/sql/40_geom.sql
Branch: geo-update
Log Message:
Moved geodetic functions to geod.c/geod.h (MAL functions still on geom.c);
removed HasZ, HasM
and get_type; moved spatial_ref_sys table and COPY INTO command to
spatial_ref_sys.sql; adde
d cleanup.md file to keep track of geo-update cleanup of geom module
diffs (truncated from 10914 to 300 lines):
diff --git a/geom/monetdb5/CMakeLists.txt b/geom/monetdb5/CMakeLists.txt
--- a/geom/monetdb5/CMakeLists.txt
+++ b/geom/monetdb5/CMakeLists.txt
@@ -10,7 +10,8 @@ if(GEOS_FOUND)
add_library(geomodule MODULE)
set(include_sql_files
- 40_geom)
+ 40_geom
+ spatial_ref_sys)
create_include_object(
SQL_LANGUAGE
diff --git a/geom/monetdb5/cleanup.md b/geom/monetdb5/cleanup.md
new file mode 100644
--- /dev/null
+++ b/geom/monetdb5/cleanup.md
@@ -0,0 +1,21 @@
+## Clean up of geom module
+### Removed C functions:
+- geometryHasZ/geoHasZ
+- geometryHasM/geoHasM
+- geoGetType
+
+### Removed MAL functions:
+- geom.hasZ
+- geom.hasM
+- geom.getType
+
+### Removed SQL functions:
+- HasZ
+- HasM
+- get_type
+
+### Moved:
+- Moved spatial_ref_sys and geometry_columns tables to **spatial_ref_sys.sql**
+- Moved COPY INTO spatial_ref_sys to **spatial_ref_sys.sql**
+- Moved Geodetic functions (except bulk versions) to **geod.c** (MAL functions
still on geom.c)
+- Moved Geodetic headers to **geod.h**
diff --git a/geom/monetdb5/geod.c b/geom/monetdb5/geod.c
new file mode 100644
--- /dev/null
+++ b/geom/monetdb5/geod.c
@@ -0,0 +1,1338 @@
+#include "geod.h"
+
+/**
+* Convertions
+*
+**/
+
+const double earth_radius = 6371.009;
+const double earth_radius_meters = 6371009;
+
+/* Converts a longitude value in degrees to radians */
+static double
+deg2RadLongitude(double lon_degrees)
+{
+ //Convert
+ double lon = M_PI * lon_degrees / 180.0;
+ //Normalize
+ //TODO PostGIS code, refactor
+ if (lon == -1.0 * M_PI)
+ return M_PI;
+ if (lon == -2.0 * M_PI)
+ return 0.0;
+ if (lon > 2.0 * M_PI)
+ lon = remainder(lon, 2.0 * M_PI);
+
+ if (lon < -2.0 * M_PI)
+ lon = remainder(lon, -2.0 * M_PI);
+
+ if (lon > M_PI)
+ lon = -2.0 * M_PI + lon;
+
+ if (lon < -1.0 * M_PI)
+ lon = 2.0 * M_PI + lon;
+
+ if (lon == -2.0 * M_PI)
+ lon *= -1.0;
+
+ return lon;
+}
+
+/* Converts a latitude value in degrees to radians */
+static double
+deg2RadLatitude(double lat_degrees)
+{
+ //Convert
+ double lat = M_PI * lat_degrees / 180.0;
+ //Normalize
+ //TODO PostGIS code, refactor
+ if (lat > 2.0 * M_PI)
+ lat = remainder(lat, 2.0 * M_PI);
+
+ if (lat < -2.0 * M_PI)
+ lat = remainder(lat, -2.0 * M_PI);
+
+ if (lat > M_PI)
+ lat = M_PI - lat;
+
+ if (lat < -1.0 * M_PI)
+ lat = -1.0 * M_PI - lat;
+
+ if (lat > M_PI_2)
+ lat = M_PI - lat;
+
+ if (lat < -1.0 * M_PI_2)
+ lat = -1.0 * M_PI - lat;
+
+ return lat;
+}
+
+/* Converts the GeoPoint from degrees to radians latitude and longitude*/
+static GeoPoint
+deg2RadPoint(GeoPoint geo)
+{
+ geo.lon = deg2RadLongitude(geo.lon);
+ geo.lat = deg2RadLatitude(geo.lat);
+ return geo;
+}
+
+/**
+ * Converts a longitude value in radians to degrees
+ */
+static double
+rad2DegLongitude(double lon_radians)
+{
+ //Convert
+ double lon = lon_radians * 180.0 / M_PI;
+ //Normalize
+ //TODO PostGIS code, refactor
+ if (lon > 360.0)
+ lon = remainder(lon, 360.0);
+
+ if (lon < -360.0)
+ lon = remainder(lon, -360.0);
+
+ if (lon > 180.0)
+ lon = -360.0 + lon;
+
+ if (lon < -180.0)
+ lon = 360 + lon;
+
+ if (lon == -180.0)
+ return 180.0;
+
+ if (lon == -360.0)
+ return 0.0;
+
+ return lon;
+}
+
+/**
+ * Converts a latitude value in radians to degrees
+ */
+static double
+rad2DegLatitude(double lat_radians)
+{
+ //Convert
+ double lat = lat_radians * 180.0 / M_PI;
+ //Normalize
+ //TODO PostGIS code, refactor
+ if (lat > 360.0)
+ lat = remainder(lat, 360.0);
+
+ if (lat < -360.0)
+ lat = remainder(lat, -360.0);
+
+ if (lat > 180.0)
+ lat = 180.0 - lat;
+
+ if (lat < -180.0)
+ lat = -180.0 - lat;
+
+ if (lat > 90.0)
+ lat = 180.0 - lat;
+
+ if (lat < -90.0)
+ lat = -180.0 - lat;
+
+ return lat;
+}
+
+/* Converts the GeoPoint from degrees to radians latitude and longitude*/
+static GeoPoint
+rad2DegPoint(GeoPoint geo)
+{
+ geo.lon = rad2DegLongitude(geo.lon);
+ geo.lat = rad2DegLatitude(geo.lat);
+ return geo;
+}
+
+/* Converts the a GEOSGeom Point into a GeoPoint */
+static GeoPoint
+geoPointFromGeom(GEOSGeom geom)
+{
+ GeoPoint geo;
+ GEOSGeomGetX(geom, &(geo.lon));
+ GEOSGeomGetY(geom, &(geo.lat));
+ return geo;
+}
+
+/* Converts the a GEOSGeom Line into GeoLines
+ Argument must be a Line geometry. */
+static GeoLines
+geoLinesFromGeom(GEOSGeom geom)
+{
+ const GEOSCoordSequence *gcs = GEOSGeom_getCoordSeq(geom);
+ GeoLines geo;
+ geo.pointCount = GEOSGeomGetNumPoints(geom);
+ //TODO Malloc fail exception?
+ geo.points = GDKmalloc(sizeof(GeoPoint) * geo.pointCount);
+ for (int i = 0; i < geo.pointCount; i++)
+ GEOSCoordSeq_getXY(gcs, i, &geo.points[i].lon,
&geo.points[i].lat);
+ //TODO Calculate Boundind Box on initializion?
+ geo.bbox = NULL;
+ return geo;
+}
+
+/* Converts the a GEOSGeom Line into GeoPolygon (with exterior ring and
zero-to-multiple interior rings)
+ Argument must be a Polygon geometry. */
+static GeoPolygon
+geoPolygonFromGeom(GEOSGeom geom)
+{
+ GeoPolygon geo;
+ //Get exterior ring GeoLines
+ geo.exteriorRing =
geoLinesFromGeom((GEOSGeom)GEOSGetExteriorRing(geom));
+ geo.interiorRingsCount = GEOSGetNumInteriorRings(geom);
+ //If there are interior rings, allocate space to their GeoLines
representation
+ if (geo.interiorRingsCount > 0)
+ //TODO Malloc fail exception?
+ geo.interiorRings = GDKmalloc(sizeof(GeoLines) *
geo.interiorRingsCount);
+ else
+ geo.interiorRings = NULL;
+ //Get interior rings GeoLines
+ for (int i = 0; i < geo.interiorRingsCount; i++)
+ geo.interiorRings[i] =
geoLinesFromGeom((GEOSGeom)GEOSGetInteriorRingN(geom, i));
+ //TODO Calculate Boundind Box on initializion?
+ geo.bbox = NULL;
+ return geo;
+}
+
+static GeoPoint
+geoPointFromLatLon(double lon, double lat)
+{
+ GeoPoint geo;
+ geo.lon = lon;
+ geo.lat = lat;
+ return geo;
+}
+
+static str
+freeGeoLines(GeoLines lines) {
+ str msg = MAL_SUCCEED;
+ //TODO Check if frees are correctly done
+ GDKfree(lines.points);
+ if (lines.bbox)
+ GDKfree(lines.bbox);
+ return msg;
+}
+
+static str
+freeGeoPolygon(GeoPolygon polygon) {
+ str msg = MAL_SUCCEED;
+ //TODO Check if frees are correctly done
+ msg = freeGeoLines(polygon.exteriorRing);
+ if (polygon.bbox)
+ GDKfree(polygon.bbox);
+ for (int i = 0; i < polygon.interiorRingsCount; i++)
+ msg = freeGeoLines(polygon.interiorRings[i]);
+ if (polygon.interiorRings)
+ GDKfree(polygon.interiorRings);
+ return msg;
+}
+
+static CartPoint3D
+cartPointFromXYZ(double x, double y, double z)
+{
+ CartPoint3D cart;
+ cart.x = x;
+ cart.y = y;
+ cart.z = z;
+ return cart;
+}
+
+//TODO Move this to first-level functions
+/* Converts Well-Known Bytes into Geos Geometries, if they are not NULL and
have the same SRID (used for geographic functions) */
+static str
+wkbGetComplatibleGeometries(wkb **a, wkb **b, GEOSGeom *ga, GEOSGeom *gb)
+{
+ str err = MAL_SUCCEED;
+
+ if (is_wkb_nil(*a) || is_wkb_nil(*b)) {
+ (*ga) = NULL;
+ (*gb) = NULL;
+ return MAL_SUCCEED;
+ }
+ (*ga) = wkb2geos(*a);
+ (*gb) = wkb2geos(*b);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]