Java Geo Tool API: getInteriorPoint does not work on an intersection between Polygon and MultiLineStringHow...

How to generate binary array whose elements with values 1 are randomly drawn

Dual Irish/Britsh citizens

Maths symbols and unicode-math input inside siunitx commands

What does Deadpool mean by "left the house in that shirt"?

Comment Box for Substitution Method of Integrals

Do native speakers use "ultima" and "proxima" frequently in spoken English?

Writing in a Christian voice

Calculate the frequency of characters in a string

Tikz: place node leftmost of two nodes of different widths

Am I eligible for the Eurail Youth pass? I am 27.5 years old

My friend is being a hypocrite

Asserting that Atheism and Theism are both faith based positions

Does .bashrc contain syntax errors?

Four married couples attend a party. Each person shakes hands with every other person, except their own spouse, exactly once. How many handshakes?

Describing a chess game in a novel

HP P840 HDD RAID 5 many strange drive failures

In the 1924 version of The Thief of Bagdad, no character is named, right?

What favor did Moody owe Dumbledore?

Why is there so much iron?

Unfrosted light bulb

How do hiring committees for research positions view getting "scooped"?

Do I need to be arrogant to get ahead?

Do US professors/group leaders only get a salary, but no group budget?

Changing Color of error messages



Java Geo Tool API: getInteriorPoint does not work on an intersection between Polygon and MultiLineString


How to find the intersection point of polygon geometry and multilinestring geometry in postgisIntersection of triangle and polygonIntersection between polylines feature to polygon in QGISIntersection between line and polygonPython QGIS reliable intersection/overlap check between points and linesIntersection of a raster and polygon in ArcGIS 10.3Using Check Geometries plugin for polygons in QGIS?Dissolving polygon with enclave does not workArea of Intersection between two polygon files in QGISDoes Redis geo have the capability for storing polygon?













0















I'm working on a Java project using Geo Tool 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 Geo Tool 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.



Thanks,



Stefano Falconetti.









share



























    0















    I'm working on a Java project using Geo Tool 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 Geo Tool 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.



    Thanks,



    Stefano Falconetti.









    share

























      0












      0








      0








      I'm working on a Java project using Geo Tool 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 Geo Tool 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.



      Thanks,



      Stefano Falconetti.









      share














      I'm working on a Java project using Geo Tool 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 Geo Tool 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.



      Thanks,



      Stefano Falconetti.







      polygon intersect





      share












      share










      share



      share










      asked 2 mins ago









      caramelleascaramelleas

      243




      243






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "79"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f315778%2fjava-geo-tool-api-getinteriorpoint-does-not-work-on-an-intersection-between-pol%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f315778%2fjava-geo-tool-api-getinteriorpoint-does-not-work-on-an-intersection-between-pol%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          (145452) 2005 RN43 Классификация | Примечания | Ссылки |...

          Щит и меч (фильм) Содержание Названия серий | Сюжет |...

          Энтрерриос (город) Содержание История | Географическое...