|
|
|
David Turner-3
|
It looks like the C API doesn't really support Coordinates. The only
way I can figure out to pass Coordinates is to use Geometry* as a parameter, and use dynamic_cast<Point *> to ensure that the Geometry is Point. This leads to long-winded code -- not to mention a lack of compile-time type-checking. I've attached a patch which demonstrates the approach I describe above. Unfortunately, it's not a very clean patch, because I realized I had forgotten to completely constify the linearref code. When I submit a final patch, I'll break the const changes out into a separate patch. The alternative is that I could simply declare Coordinate in the C API. I'm not sure what consequences that would have, or why it was rejected in the first place -- but it would simplify the code here and perhaps elsewhere. Please let me know what approach is most likely to get my patch accepted, or if there's something obvious that I'm missing. [c_api_initial_stab.diff] Index: source/linearref/LinearIterator.cpp =================================================================== --- source/linearref/LinearIterator.cpp (revision 2619) +++ source/linearref/LinearIterator.cpp (working copy) @@ -38,7 +38,7 @@ return loc.getSegmentIndex(); } -LinearIterator::LinearIterator(Geometry* linear) : +LinearIterator::LinearIterator(const Geometry* linear) : vertexIndex(0), componentIndex(0), linear(linear), @@ -48,7 +48,7 @@ } -LinearIterator::LinearIterator(Geometry* linear, const LinearLocation& start): +LinearIterator::LinearIterator(const Geometry* linear, const LinearLocation& start): vertexIndex(segmentEndVertexIndex(start)), componentIndex(start.getComponentIndex()), linear(linear), @@ -57,7 +57,7 @@ loadCurrentLine(); } -LinearIterator::LinearIterator(Geometry* linear, unsigned int componentIndex, unsigned int vertexIndex) : +LinearIterator::LinearIterator(const Geometry* linear, unsigned int componentIndex, unsigned int vertexIndex) : vertexIndex(vertexIndex), componentIndex(componentIndex), linear(linear), Index: source/linearref/LengthIndexOfPoint.cpp =================================================================== --- source/linearref/LengthIndexOfPoint.cpp (revision 2619) +++ source/linearref/LengthIndexOfPoint.cpp (working copy) @@ -36,28 +36,28 @@ namespace linearref // geos.linearref { -double LengthIndexOfPoint::indexOf(Geometry *linearGeom, Coordinate& inputPt) +double LengthIndexOfPoint::indexOf(const Geometry *linearGeom, const Coordinate& inputPt) { LengthIndexOfPoint locater(linearGeom); return locater.indexOf(inputPt); } -double LengthIndexOfPoint::indexOfAfter(Geometry *linearGeom, Coordinate& inputPt, double minIndex) +double LengthIndexOfPoint::indexOfAfter(const Geometry *linearGeom, const Coordinate& inputPt, double minIndex) { LengthIndexOfPoint locater(linearGeom); return locater.indexOfAfter(inputPt, minIndex); } -LengthIndexOfPoint::LengthIndexOfPoint(Geometry *linearGeom): +LengthIndexOfPoint::LengthIndexOfPoint(const Geometry *linearGeom): linearGeom(linearGeom) {} -double LengthIndexOfPoint::indexOf(Coordinate& inputPt) +double LengthIndexOfPoint::indexOf(const Coordinate& inputPt) const { return indexOfFromStart(inputPt, -1.0); } -double LengthIndexOfPoint::indexOfAfter(Coordinate& inputPt, double minIndex) +double LengthIndexOfPoint::indexOfAfter(const Coordinate& inputPt, double minIndex) const { if (minIndex < 0.0) return indexOf(inputPt); @@ -78,7 +78,7 @@ return closestAfter; } -double LengthIndexOfPoint::indexOfFromStart(Coordinate& inputPt, double minIndex) +double LengthIndexOfPoint::indexOfFromStart(const Coordinate& inputPt, double minIndex) const { double minDistance = numeric_limits<double>::max(); @@ -107,8 +107,9 @@ return ptMeasure; } -double LengthIndexOfPoint::segmentNearestMeasure(LineSegment* seg, Coordinate& inputPt, - double segmentStartMeasure) +double LengthIndexOfPoint::segmentNearestMeasure(const LineSegment* seg, + const Coordinate& inputPt, + double segmentStartMeasure) const { // found new minimum, so compute location distance of point double projFactor = seg->projectionFactor(inputPt); Index: source/headers/geos/linearref/LinearIterator.h =================================================================== --- source/headers/geos/linearref/LinearIterator.h (revision 2619) +++ source/headers/geos/linearref/LinearIterator.h (working copy) @@ -58,7 +58,7 @@ const geom::LineString *currentLine; unsigned int vertexIndex; unsigned int componentIndex; - geom::Geometry *linear; + const geom::Geometry *linear; const unsigned int numLines; /** @@ -74,7 +74,7 @@ * * @param linear the linear geometry to iterate over */ - LinearIterator(geom::Geometry *linear); + LinearIterator(const geom::Geometry *linear); /** * Creates an iterator starting at @@ -83,7 +83,7 @@ * @param linear the linear geometry to iterate over * @param start the location to start at */ - LinearIterator(geom::Geometry *linear, const LinearLocation& start); + LinearIterator(const geom::Geometry *linear, const LinearLocation& start); /** * Creates an iterator starting at @@ -93,7 +93,7 @@ * @param componentIndex the component to start at * @param vertexIndex the vertex to start at */ - LinearIterator(geom::Geometry *linear, unsigned int componentIndex, unsigned int vertexIndex); + LinearIterator(const geom::Geometry *linear, unsigned int componentIndex, unsigned int vertexIndex); /** * Tests whether there are any vertices left to iterator over. Index: source/headers/geos/linearref/LengthIndexOfPoint.h =================================================================== --- source/headers/geos/linearref/LengthIndexOfPoint.h (revision 2619) +++ source/headers/geos/linearref/LengthIndexOfPoint.h (working copy) @@ -38,18 +38,19 @@ { private: - geom::Geometry *linearGeom; + const geom::Geometry *linearGeom; - double indexOfFromStart(geom::Coordinate& inputPt, double minIndex); + double indexOfFromStart(const geom::Coordinate& inputPt, const double minIndex) const; - double segmentNearestMeasure(geom::LineSegment *seg, geom::Coordinate& inputPt, - double segmentStartMeasure); + double segmentNearestMeasure(const geom::LineSegment *seg, + const geom::Coordinate& inputPt, + double segmentStartMeasure) const; public: - static double indexOf(geom::Geometry *linearGeom, geom::Coordinate& inputPt); + static double indexOf(const geom::Geometry *linearGeom, const geom::Coordinate& inputPt); - static double indexOfAfter(geom::Geometry *linearGeom, geom::Coordinate& inputPt, double minIndex); + static double indexOfAfter(const geom::Geometry *linearGeom, const geom::Coordinate& inputPt, double minIndex); - LengthIndexOfPoint(geom::Geometry *linearGeom); + LengthIndexOfPoint(const geom::Geometry *linearGeom); /** * Find the nearest location along a linear {@link Geometry} to a given point. @@ -57,7 +58,7 @@ * @param inputPt the coordinate to locate * @return the location of the nearest point */ - double indexOf(geom::Coordinate& inputPt); + double indexOf(const geom::Coordinate& inputPt) const; /** * Finds the nearest index along the linear {@link Geometry} @@ -74,7 +75,7 @@ * @param minLocation the minimum location for the point location * @return the location of the nearest point */ - double indexOfAfter(geom::Coordinate& inputPt, double minIndex); + double indexOfAfter(const geom::Coordinate& inputPt, double minIndex) const; }; } Index: capi/geos_c.cpp =================================================================== --- capi/geos_c.cpp (revision 2619) +++ capi/geos_c.cpp (working copy) @@ -883,4 +883,11 @@ GEOSSTRtree_destroy_r( handle, tree ); } +double +GEOSLengthIndexOfPoint_indexOf (const geos::geom::Geometry *g, + const geos::geom::Geometry *p) +{ + return GEOSLengthIndexOfPoint_indexOf_r (handle, g, p); +} + } /* extern "C" */ Index: capi/geos_ts_c.cpp =================================================================== --- capi/geos_ts_c.cpp (revision 2619) +++ capi/geos_ts_c.cpp (working copy) @@ -48,6 +48,7 @@ #include <geos/operation/union/CascadedPolygonUnion.h> #include <geos/operation/buffer/BufferOp.h> #include <geos/operation/buffer/BufferParameters.h> +#include <geos/linearref/LengthIndexOfPoint.h> #include <geos/geom/BinaryOp.h> #include <geos/util/IllegalArgumentException.h> #include <geos/version.h> @@ -4299,5 +4300,30 @@ } } +double +GEOSLengthIndexOfPoint_indexOf_r(GEOSContextHandle_t extHandle, + const geos::geom::Geometry *g, + const geos::geom::Geometry *p) +{ + const geos::geom::Point* point = dynamic_cast<const geos::geom::Point*>(p); + if (!point) { + if ( 0 == extHandle ) + { + return -1.0; + } + GEOSContextHandleInternal_t *handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle); + if ( 0 == handle->initialized ) + { + return -1.0; + } + + handle->ERROR_MESSAGE("third argument of GEOSLengthIndexOfPoint_indexOf_r must be Point*"); + return -1.0; + } + const geos::geom::Coordinate* inputPt = p->getCoordinate(); + return geos::linearref::LengthIndexOfPoint::indexOf(g, *inputPt); +} + + } /* extern "C" */ _______________________________________________ geos-devel mailing list [hidden email] http://lists.osgeo.org/mailman/listinfo/geos-devel |
||||||||||||||||
|
Paul Ramsey-3
|
Speaking from the PostGIS side, the CAPI is mostly an outgrowth of
meeting our use cases, which are build-geometries-and-run-a-test and build-geometries-and-get-a-new-geometry. All our fine-grained access to geometry internals is done back in PostGIS land, not against the GEOS objects. Hence, no CAPI infrastructure for that. Basically, if the CAPI doesn't already support use-case-x then you are in open ground and will be the primary user of said use case if you add it to the CAPI. P. On Fri, Aug 14, 2009 at 9:50 AM, David Turner<[hidden email]> wrote: > It looks like the C API doesn't really support Coordinates. The only > way I can figure out to pass Coordinates is to use Geometry* as a > parameter, and use dynamic_cast<Point *> to ensure that the Geometry is > Point. This leads to long-winded code -- not to mention a lack of > compile-time type-checking. > > I've attached a patch which demonstrates the approach I describe above. > Unfortunately, it's not a very clean patch, because I realized I had > forgotten to completely constify the linearref code. When I submit a > final patch, I'll break the const changes out into a separate patch. > > The alternative is that I could simply declare Coordinate in the C API. > I'm not sure what consequences that would have, or why it was rejected > in the first place -- but it would simplify the code here and perhaps > elsewhere. > > Please let me know what approach is most likely to get my patch > accepted, or if there's something obvious that I'm missing. > > _______________________________________________ > geos-devel mailing list > [hidden email] > http://lists.osgeo.org/mailman/listinfo/geos-devel > geos-devel mailing list [hidden email] http://lists.osgeo.org/mailman/listinfo/geos-devel |
|
David Turner-3
|
I have decided to do a fairly minimal C API, on the theory that it's
better to do too little than to do too much. The one wrinkle I added was normalized versions of interpolate and project, for compatibility with postgis's st_line_locate_point. http://trac.osgeo.org/geos/ticket/285#comment:1 Does that look good? On Fri, 2009-08-14 at 09:57 -0700, Paul Ramsey wrote: > Speaking from the PostGIS side, the CAPI is mostly an outgrowth of > meeting our use cases, which are build-geometries-and-run-a-test and > build-geometries-and-get-a-new-geometry. All our fine-grained access > to geometry internals is done back in PostGIS land, not against the > GEOS objects. Hence, no CAPI infrastructure for that. > > Basically, if the CAPI doesn't already support use-case-x then you are > in open ground and will be the primary user of said use case if you > add it to the CAPI. _______________________________________________ geos-devel mailing list [hidden email] http://lists.osgeo.org/mailman/listinfo/geos-devel |
||||||||||||||||
| Free Embeddable Forum Powered by Nabble | Help |