Changeset: 6ca55805d7cd for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/6ca55805d7cd
Modified Files:
geom/monetdb5/geod.c
geom/monetdb5/geom.c
Branch: geo-update
Log Message:
Fix non-existing bounding box on polygon for distancegeographic, makeline
temporary fix
diffs (161 lines):
diff --git a/geom/monetdb5/geod.c b/geom/monetdb5/geod.c
--- a/geom/monetdb5/geod.c
+++ b/geom/monetdb5/geod.c
@@ -174,6 +174,8 @@ geoLinesFromGeom(GEOSGeom geom)
return geo;
}
+static BoundingBox * boundingBoxLines(GeoLines lines);
+
/* Converts the a GEOSGeom Line into GeoPolygon (with exterior ring and
zero-to-multiple interior rings)
Argument must be a Polygon geometry. */
static GeoPolygon
@@ -192,8 +194,8 @@ geoPolygonFromGeom(GEOSGeom geom)
//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;
+ // If the geometry doesn't have BoundingBoxe, calculate it
+ geo.bbox = boundingBoxLines(geo.exteriorRing);
return geo;
}
@@ -722,18 +724,12 @@ geoDistanceSingle(GEOSGeom aGeom, GEOSGe
/* Line/LinearRing and Polygon */
GeoLines a = geoLinesFromGeom(aGeom);
GeoPolygon b = geoPolygonFromGeom(bGeom);
- // If the geometry doesn't have BoundingBoxe, calculate it
- if (b.bbox == NULL)
- b.bbox = boundingBoxLines(b.exteriorRing);
distance = geoDistanceLinePolygon(a, b);
freeGeoLines(a);
freeGeoPolygon(b);
} else if (dimA == 2 && dimB == 1) {
/* Polygon and Line/LinearRing */
GeoPolygon a = geoPolygonFromGeom(aGeom);
- // If the geometry doesn't have BoundingBoxe, calculate it
- if (a.bbox == NULL)
- a.bbox = boundingBoxLines(a.exteriorRing);
GeoLines b = geoLinesFromGeom(bGeom);
distance = geoDistanceLinePolygon(b, a);
freeGeoPolygon(a);
@@ -742,11 +738,6 @@ geoDistanceSingle(GEOSGeom aGeom, GEOSGe
/* Polygon and Polygon */
GeoPolygon a = geoPolygonFromGeom(aGeom);
GeoPolygon b = geoPolygonFromGeom(bGeom);
- // If the geometries don't have BoundingBoxes, calculate them
- if (a.bbox == NULL)
- a.bbox = boundingBoxLines(a.exteriorRing);
- if (b.bbox == NULL)
- b.bbox = boundingBoxLines(b.exteriorRing);
distance = geoDistancePolygonPolygon(a, b);
freeGeoPolygon(a);
freeGeoPolygon(b);
diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -3384,14 +3384,12 @@ wkbMakeLineAggr(wkb **outWKB, bat *bid)
return err;
}
-static str
+/*static str
wkbMakeLineAggrArray(wkb **outWKB, wkb **inWKB_array, int size) {
str msg = MAL_SUCCEED;
int i;
wkb *aWKB, *bWKB;
- /* TODO: what should be returned if the input is less than
- * two rows? --sjoerd */
if (size == 0) {
if ((*outWKB = wkbNULLcopy()) == NULL)
throw(MAL, "aggr.MakeLine", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
@@ -3420,6 +3418,70 @@ wkbMakeLineAggrArray(wkb **outWKB, wkb *
GDKfree(aWKB);
}
return msg;
+}*/
+
+static str
+wkbExtractPointToCoordSeq(GEOSCoordSeq *outCoordSeq, wkb *inWKB, int index) {
+ double x,y;
+ str msg = MAL_SUCCEED;
+ GEOSGeom inGeometry;
+ const GEOSCoordSequence *inCoordSeq = NULL;
+
+ inGeometry = wkb2geos(inWKB);
+ if (!inGeometry) {
+ throw(MAL, "geom.MakeLine", SQLSTATE(38000) "Geos operation
wkb2geos failed");
+ }
+ inCoordSeq = GEOSGeom_getCoordSeq(inGeometry);
+ GEOSCoordSeq_getX(inCoordSeq, 0, &x);
+ GEOSCoordSeq_getY(inCoordSeq, 0, &y);
+ if (!GEOSCoordSeq_setX(*outCoordSeq, index, x) ||
+ !GEOSCoordSeq_setY(*outCoordSeq, index, y)) {
+ throw(MAL, "geom.MakeLine", SQLSTATE(38000) "Geos operation
GEOSCoordSeq_set[XY] failed");
+ }
+ return msg;
+}
+
+static str
+wkbMakeLineAggrArray2(wkb **outWKB, wkb **inWKB_array, int size) {
+ str msg = MAL_SUCCEED;
+ int i;
+ wkb *aWKB, *bWKB;
+ GEOSGeom outGeometry;
+ GEOSCoordSeq outCoordSeq = NULL;
+
+ /* TODO: what should be returned if the input is less than
+ * two rows? --sjoerd */
+ if (size == 0) {
+ if ((*outWKB = wkbNULLcopy()) == NULL)
+ throw(MAL, "aggr.MakeLine", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
+ return MAL_SUCCEED;
+ }
+ aWKB = inWKB_array[0];
+ if (size == 1) {
+ msg = wkbFromWKB(outWKB, &aWKB);
+ if (msg) {
+ freeException(msg);
+ throw(MAL, "aggr.MakeLine", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
+ }
+ return MAL_SUCCEED;
+ }
+ bWKB = inWKB_array[1];
+ //create the first line using the first two geometries
+ //msg = wkbMakeLine(outWKB, &aWKB, &bWKB);
+ outCoordSeq = GEOSCoordSeq_create(size, 2);
+
+ msg = wkbExtractPointToCoordSeq(&outCoordSeq, aWKB, 0);
+ msg = wkbExtractPointToCoordSeq(&outCoordSeq, bWKB, 1);
+
+ // add one more segment for each following row
+ for (i = 2; msg == MAL_SUCCEED && i < size; i++) {
+ msg = wkbExtractPointToCoordSeq(&outCoordSeq, inWKB_array[i],
i);
+ }
+ if ((outGeometry = GEOSGeom_createLineString(outCoordSeq)) == NULL) {
+ msg = createException(MAL, "geom.MakeLine", SQLSTATE(38000)
"Geos operation GEOSGeom_createLineString failed");
+ }
+ *outWKB = geos2wkb(outGeometry);
+ return msg;
}
//TODO Check SRID
@@ -3510,14 +3572,14 @@ wkbMakeLineAggrSubGroupedCand(bat *outid
if (grp != lastGrp) {
if (lastGrp != (oid)-1) {
- msg = wkbMakeLineAggrArray(&lines[lastGrp],
lineGroup, position);
+ msg = wkbMakeLineAggrArray2(&lines[lastGrp],
lineGroup, position);
position = 0;
}
lastGrp = grp;
}
lineGroup[position++] = inWKB;
}
- msg = wkbMakeLineAggrArray(&lines[lastGrp], lineGroup, position);
+ msg = wkbMakeLineAggrArray2(&lines[lastGrp], lineGroup, position);
if (BUNappendmulti(out, lines, ngrp, false) != GDK_SUCCEED) {
//TODO Free out BAT
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]