sammy_kayd
sammy_kayd

Reputation: 11

How to convert Longitude and Latitude to points and using the points in drawing a polygon

I'm new to GIS applications and I have a little problem. I'm trying to plot a polygon using geographic coordinates but I need to convert these coordinates to points before I can use them in plotting the polygon. I don't know how to convert these coordinates to points to use for the polygon. I spent all my yesterday finding out how to do this but I really still don't get it. I tried using the geography datatype in ms sql server 2008 but I couldn't find a java api in retrieving the polygon or the converted coordinates. Please help me with a sample code on how to do this.

Thanks a lot people!!!

This is my code. 'Code'

double earth=6371;
double focal=500;

double lat= 47.653 ;
double lon = -122.358  ;

double latitude = lat*Math.PI/180;
double longitude = lon*Math.PI/180;

double x = earth * Math.sin(latitude)*Math.cos(longitude);

double y = earth * Math.sin(latitude)*Math.sin(longitude);

double z = earth * Math.cos(latitude);

double projectedX = x*focal /(focal+z);

double projectedY = y * focal / (focal+z);

int magx = (int) Math.round(projectedX * 5); 
int magy = (int) Math.round(projectedY *5);

System.out.println ("MAG X : "+magx);
System.out.println ("MAG Y : "+magy);

I just plug in d mag x and y into my polygon but nothing comes up.

Upvotes: 0

Views: 1698

Answers (1)

Alastair Aitchison
Alastair Aitchison

Reputation: 3532

This is the syntax for creating and retrieving a geography Polygon in SQL Server from a set of n coordinates:

DECLARE @Polygon geography;
SET @Polygon = geography::STPolyFromText('POLYGON((Lon1 Lat1, Lon2 Lat2, ... Lonn Latn, Lon1 Lat1))', 4326); 
SELECT @Polygon;

(This assumes you're using geographic coordinates relative to the WGS84 datum. If you don't know what that means, they probably are.)

Upvotes: 2

Related Questions