[geotk] Circle Polygon
theuns
theunsheydenrych at gmail.com
Thu Sep 17 06:04:38 EDT 2009
HI Martin
I tried to calculate the circle with the GeodeticCalculator with
EPSG:3395 and with WGS84 Geographic projection.
Attached is the results for the tests.
The results does not look correctly, for the CRS_3395 i excpexted a egg
shaped circle ,and for the WGS84 a "round" circle.
For the test a took a world shapefile and the shapefile is in geographic
coordinates and added a circle at the southern tip of south america,
will see the shapefile circle also rendered in the attached images.
I mailed this shapefile to Johann, if you would like to use it, or i can
mail it again to you if you would like to have it.
I then used a point more or less in the middle of the shapefile circle ,
to generate a circle of 100km radius in more or less the same place.
Below is the code i used to to this:
The radius value i used is 100000
//Centre point of circle used for EPSG:3395
Geometry centrePoint = StaticGeometry.geomFromWKT("POINT
(-7144442.991431108 -7277982.720580169)");
//Centre point of circle used for WGS84 Geographic
//Geometry centrePoint = StaticGeometry.geomFromWKT("POINT (-64.174
-54.872)");
protected Geometry getCircle(Geometry centrePoint, double radius,
CoordinateReferenceSystem objectiveCRS) {
Geometry resultCircle = null;
final Point jtsPoint = (Point) centrePoint;
double x = jtsPoint.getCoordinate().x;
double y = jtsPoint.getCoordinate().y;
//List for result coordinates
List<Coordinate> circleCoords = new ArrayList<Coordinate>();
//double array for buffer result
double[][] circlePoint;
try {
//Work from 180 degrees down to -180 degrees in 10 degree
increments
for (int azm = 180; azm >= -180; azm -= 10) {
//get the point on the circle ring for a distance from
the centre point at a certain angle
circlePoint = buffer(x, y, objectiveCRS, radius, azm);
//make a coordinate of the result and add it to the
coords list
circleCoords.add(new Coordinate(circlePoint[0][0],
circlePoint[0][1]));
System.out.println( circlePoint[0][0] + "," +
circlePoint[0][1]);
}
} catch (IndexOutOfBoundsException ex) {
Logger.getLogger(UserOverlayFrame.class.getName()).log(Level.SEVERE,
null, ex);
} catch (IllegalArgumentException ex) {
Logger.getLogger(UserOverlayFrame.class.getName()).log(Level.SEVERE,
null, ex);
} catch (TransformException ex) {
Logger.getLogger(UserOverlayFrame.class.getName()).log(Level.SEVERE,
null, ex);
}
//Create a polygon from the coordinates list
Coordinate[] ringCoords = circleCoords.toArray(new
Coordinate[circleCoords.size() + 1]);
ringCoords[circleCoords.size()] = circleCoords.get(0);
GeometryFactory GF = new GeometryFactory();
LinearRing ring = GF.createLinearRing(ringCoords);
resultCircle = GF.createPolygon(ring, new LinearRing[0]);
return resultCircle;
}
private double[][] buffer(double x, double y, CoordinateReferenceSystem
crs, double distance, double angle) throws IndexOutOfBoundsException,
IllegalArgumentException, TransformException {
//create array for the result
double[][] result = new double[1][2];
//set up the GeodeticCalculator with the objective CRS of the
mapwidget
final GeodeticCalculator gc = new GeodeticCalculator(crs);
//set up the startPos with the objective CRS of the mapwidget
final GeneralDirectPosition startPos = new
GeneralDirectPosition(crs);
//Populate the StartingPosition in the GeodeticCalculator,
//in this case its the centre point of the circle
startPos.ordinates[0] = x;
startPos.ordinates[1] = y;
gc.setStartingPosition(startPos);
//Set the direction and distance for the point to be computed
gc.setDirection(angle, distance);
//Get the computed result
DirectPosition destPos = gc.getDestinationPosition();
//Populate the result array, with computed x,y values
result[0][0] = destPos.getOrdinate(0);
result[0][1] = destPos.getOrdinate(1);
return result;
}
I think the problem is in the GeodedicCalculator when converting the
values back to the supplied CRS, or i just dont use the
GeodedicCalculator correctly?
Thanks
Theuns Heydenrych
On Wed, 2009-09-16 at 21:23 +0200, Martin Desruisseaux wrote:
> theuns a écrit :
> > The suggestion is now to use the GeodedicCalculator to work out the
> > values for the circle, for a certain CRS, this makes more sense to me,
> > since the geodedicCalculator will take in account the CRS.
> >
> > Do you agree?
>
> Yes, it is the best approach I can imagine right now.
>
> Regards,
>
> Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CRS_3395.png
Type: image/png
Size: 15672 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/geotoolkit/attachments/20090917/b195a964/CRS_3395-0001.png
-------------- next part --------------
A non-text attachment was scrubbed...
Name: WGS84_Circle.png
Type: image/png
Size: 18651 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/geotoolkit/attachments/20090917/b195a964/WGS84_Circle-0001.png
More information about the Geotoolkit
mailing list