3

I am trying to get the end points of a polygon which presents a building in a shp file.

Do you know if there is any function in geotools or the steps that i have to follow to do this?

i find a relative question: how would one get the end points of a polyline? But it is not what i need.

Elena Valari
  • 133
  • 4
  • 4
    what do you mean by the end points of a polygon? they are closed by definition so there is no beginning or end, do you mean max and min in some direction? – Ian Turton Oct 06 '16 at 10:40
  • Are you referring to the vertices of the polygon representing a building? – Hasan Mustafa Oct 06 '16 at 10:41
  • Yes, i am talking about the vertices of the polygon representing a building..? do you know how i can "identify" them? – Elena Valari Oct 06 '16 at 13:38

1 Answers1

1

If you got your Polygons from your shapefile you can get all vertices using JTS getCoordinates() method:

// get first coordinate
Coordinate first = yourPolygon.getCoordinates()[0];
// get last coordinate (same as first)
Coordinate last = yourPolygon.getCoordinates()[yourPolygon.getCoordinates().length-1];
// get last coordinate before closing
Coordinate lastBeforeClosing = yourPolygon.getCoordinates()[yourPolygon.getCoordinates().length-2];
Lars
  • 2,197
  • 2
  • 18
  • 33