0

I'm working on a Java project using GeoTools API that want to get the interior point getInteriorPoint(), from the geometry coming from an intersection between a Polygon and a MultiLineString. Please note that the same approach works perfectly between a Polygon and MultiPolygon, so between objects with the same number of dimensions, I guess.

Let me explain better with a snippet of code (java GeoTools API version 15.1):

if(feature.getDefaultGeometry() instanceof MultiLineString){

   MultiLineString multiLineString = ((MultiLineString) feature.getDefaultGeometry());

   //Interior point on intersection
   Coordinate intersectionInteriorPoint = this.getInteriorPointForIntersectedArea(polygon, multiLineString, sourceCRS);

}

where the getInteriorPointForIntersectedArea(..) is as this:

   /**
     * Compute the interior point for the overlapping area 
     * between the search geometry and an intersected geometry
     * @param one
     * @param two
     * @return the coordinate in the target output reference CRS
     */
    private Coordinate getInteriorPointForIntersectedArea(Polygon one, 
                                                          MultiLineString two, 
                                                          CoordinateReferenceSystem sourceCRS, 
                                                          Coordinate waypointCoordinate){

        com.vividsolutions.jts.geom.Geometry lineString = (com.vividsolutions.jts.geom.Geometry) one.intersection(two);

        System.out.println("Geometry type: " + lineString.getGeometryType());

        Coordinate interiorPointCoordinate = lineString.getInteriorPoint().getCoordinate();

        Coordinate interiorPointCoordinateChanged = null;
        try {
            interiorPointCoordinateChanged = CoordinateReferenceSystemTools.FromToCRS(sourceCRS, 
                                                                                      org.geotools.referencing.crs.DefaultGeographicCRS.WGS84, 
                                                                                      interiorPointCoordinate, 
                                                                                      true);
        } catch (FactoryException | 
                 TransformException | 
                 NullPointerException | 
                 IllegalArgumentException e) {

                 interiorPointCoordinateChanged = new Coordinate(0,0);
                 System.err.println("Unable to extract feature interior point: ");
                 e.printStackTrace();
        }

        System.out.println("MultilineString interior point lat: " + interiorPointCoordinateChanged.y + " lon: " + interiorPointCoordinateChanged.x);
        return interiorPointCoordinateChanged;  
    }

I apply this on multiple features and sometimes the same code return the correct interior point. Some other times, the method below fails with exception:

*java.lang.IllegalArgumentException: Argument "source" should not be null.
    at org.geotools.geometry.jts.JTS.ensureNonNull(JTS.java:135)
    at org.geotools.geometry.jts.JTS.transform(JTS.java:460)*

Looking into JTS at line 135, I find that name = "source" coming into this method, as null value in object when the exception happens:

private static void ensureNonNull(final String name, final Object object)
            throws IllegalArgumentException {
        if (object == null) {
            throw new IllegalArgumentException(Errors.format(ErrorKeys.NULL_ARGUMENT_$1, name));
        }
    }

I have discovered so, that the exception occurs when the Point coming out from the call:

lineString.getInteriorPoint()

is a POINT EMPTY

Does anyone of you knows why sometimes, getInteriorPoint() returns a POINT EMPTY ? This happens to me only when I try to call getInteriorPoint() on a geometry coming from the interesection between w Polygon and a MultiLineString.

  • 2
    The intersection between two polygons is a polygon, but between a line and a polygon is a line. Perhaps getInteriorPoint doesn't return a point along a line. – Vince Mar 18 at 1:01
  • Lines can't have interior points en.wikipedia.org/wiki/Interior_(topology). – user30184 Mar 18 at 7:00
  • Hi, lines can have, I tested it successfully for other scenarios. The fact is that if the line is not valid the API is so good that it returns for getInteriorPoint, an empty point. Still checking with the GIS though. – caramelleas Mar 18 at 8:47
  • @user30184 In terms of Clementini algebra and calculus, the interior is the part of a shape which is not exterior, and the exterior of a line is the endpoints, so the interior of a line would be the part of the line between the endpoints. – Vince Mar 18 at 13:20
  • Thank you @Vince, for pointing out the difference with general topology. For future reference en.wikipedia.org/wiki/DE-9IM Note that in this article the words interior and boundary are used in the sense used in algebraic topology and manifold theory, not in the sense used in general topology: e.g. by the interior of a line segment we mean the line segment without its endpoints and by its boundary, the two endpoints (in the general topology sense, the interior of a line segment in the plane is empty and the line segment is its own boundary). – user30184 Mar 18 at 15:24
1

Looking at the code the most likely reason that you would get an empty point back is that your line string is empty. That is, there is no intersection between your line and the polygon.

To be sure you will need to print out the polygon and line, then check them in a GIS. I usually use the QuickWKT plugin in QGIS for this purpose.

  • Correct, chcking the same I saw this morning that the feature is somehow broken, with two points only and with the same coordinates, so it has no dimensions and so it cannot have an interior point. So far this seems to be the cause. – caramelleas Mar 18 at 8:45
0

Confirmed, getInteriorPoint on a line is possible and above issue was due to bad data. examples of good and bad geometries follow:

GOOD type: MultiLineString bounddim:0 numgeom:1 numpoi:23 SSRID: 0 ID: 80517639

BAD type: MultiLineString bounddim:-1 numgeom:1 numpoi:2 SSRID: 0 ID: 83948614

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.