How do I convert SRID 3857 formatted geometery coordinates into to decimal degrees?
My current stack is SQL Server 2014 and C#.
You cannot convert them directly in SQL Server. Quite simply it wasn't built to reinvent the Reprojection of spatial data in one datum to another. When using SqlGeography, you can of course swap between SRIDs when both sets of coordinates use the same coordinate-type (decimal-degrees or grid-based), however when using SqlGeometry, they are simply planar coordinates based on the scale set by the bounds of the data you have and setting the SRID merely "groups" like-SRID spatial objects.
You'll need a Third-Party library or tool to do this for you. Geographika notes some options at the following SO Link:
Know of any C# spatial data libraries?
See Convert coordinate systems using SQLGeometery
SRID 4326 seems to work well enough.
http://spatialreference.org/ref/epsg/4326/
Related
I have a list of coordinates that I want to plot on Google Maps, but I can't figure out how to do that. The coordinates, depending on how I plot them, appear to be all around the globe, while they should be placed in Trondheim, Norway. (And the application I have extracted them from successfully places them in Trondheim, so I know they are correct.)
A normal Google Maps coordinate from Trondheim looks like this:
63.4304, 10.395069
My coordinates, however, look like this:
long, lat
1154262, 9182277
1143762, 9184473
1157168, 9194133
1157375, 9200167
1164505, 9209786
I believe that these are in some kind of WGS84 format, but as I am a complete novice on this field, I am not completely sure. I think so because of the headers in the XML I have extracted them from:
<rss version="2.0"
xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
xmlns:georss="http://www.georss.org/georss"
xmlns:gml="http://www.opengis.net/gml"
xmlns:mappoint="http://virtualearth.msn.com/apis/annotate#">
When I try to use this coordinate converter, it returns coordinates in Kazakhstan. I am utterly confused. All other converters I have tried either returns locations in strange countries or in the middle of the oceans, or they fail to convert my data at all.
Does anybody here know what kind of coordinates I have, and how I can convert them to normal latitude and longitude degrees?
A formula is enough, but if there exists any libraries for this, I am using C# as development language. Any other languages would suffice, however, as I am probably able to convert them to my own anyway.
WGS-84 is Spherical Mercator, the projection system used by Google, so the coordinates you have provided are obviously not. Unfortunately for any formula to work you will need to find out the projection that your points are in.
Some more detailed information on projection is available here: http://courses.washington.edu/gis250/lessons/projection/
And a library to convert between common coordinate systems in .net is available at: http://www.doogal.co.uk/dotnetcoords.php.
Would it be possible for you to open the map layer in an GIS program such as: http://www.qgis.org/en/site/ and use the options available to determine the projection of the layer?
Some tips for identifying the coordinate system (written for ARCGIS but the programs are similar): http://resources.arcgis.com/en/help/main/10.1/index.html#//003r00000004000000 https://gis.stackexchange.com/questions/7839/best-practices-for-identifying-the-unknown-coordinate-system-of-a-shapefile
I can use the following SQL to calculate the distance between a fixed location and the location against the venues in the database.
SELECT Location.STDistance(geography::Point(51, -2, 4326)) * 0.00062137119 FROM Venues
Please note the distance returned is in miles and the Location field is a geography type.
I was wondering what is the equivalent of this in .NET which would return the same values. This method would have the following signature:
public static double Distance(location1Latitude, location1Longitude, location2Latitude, location2Longitude) {
return ...;
}
I know I could call the database method in .NET but I don't wish to do this. I'm hoping there is a formula to calculate the distance. Thanks
I believe you can simply add Microsoft.SqlServer.Types.dll as a reference and then use the SqlGeometry type like any other .NET type, including calling the STDistance method.
You would need to compute the Geographical distance to compute the distance manually. There are many different techniques and formulas to do this, each with different underlying assumptions (ie: a spherical earth, ellipsoidal earth, etc).
A common option is the haversine formula, with a C# implementation available here.
this is very well explained here.
Shortly: with EF5 (to be more specific, with .net 4.5) Microsoft included the type DbGeography. Let say you already have a bunch of lat/long, you can then create a DbGeography object easily using an helper like:
public static DbGeography CreatePoint(double latitude, double longitude)
{
var text = string.Format(CultureInfo.InvariantCulture.NumberFormat,
"POINT({0} {1})", longitude, latitude);
// 4326 is most common coordinate system used by GPS/Maps
return DbGeography.PointFromText(text, 4326);
}
Once you got a two or more points (DbGeography) you got everything to calculate the Distance between them:
var distance = point1.Distance(point2)
I am importing data that was exported from a vb6 application into a new app made in c#.net.
The pixel coordinates in the data are in vbPixels. Is there a way to convert them into the real pixel coordinate? The bitmap is 800x500 and the pixels are like x=2265 y=1620.
Use these functions from .NET:
ToPixelsX - Used for coordinate conversion.
ToPixelsY - Used for coordinate conversion.
And read this to understand what is going on. Twips have a very special definition that is dependent on resolution.
In my previous answer I assumed that you knew that the give coordinate was the size of the image.
in VB6 you can use
Screen.TwipsPerPixelx
and
Screen.TwipsPerPixelY
These are almost always 15, but the user could change some settings which might result in other values (i am not sure which settings though :))
I need to convert a user's UTM input (WGS 1984) into Decimal Degrees, preferably using ESRI's ArcGis. I've already got the code to retrieve the zone (formatted like 14N, 22S, etc.) and the easting and northing factors. What do I do from here?
Edit: we expect the input as a string like: 14N 423113mE 4192417mN. I can easily extract the numbers (and a character) 14, N, 423113, and 4192417 from the string above. I just need to somehow translate that to Decimal Degrees.
There is no specific information about input data.
Here is some general info to start from:
The easiest way is to use Geoprocessing engine to reproject the whole feature class. Use C# class for Project tool from Data Management toolbox.
Another way is to use Project method of IGeometry is you want project only several features.
EDIT: for your input data use solution 2.
One more easier way is to use .NET port of open-source library Proj.4 - Proj4Net. For such simple task it is much more easier to use than ArcObjects classes.
Does anyone know of a C# library that can parse geo coordinates from one string without having to specify the format upfront. The goal is to enable "google like" data entry and interpretation.
Some formats that should be supported:
"12 34.56'N 123 45.55'E"
"12°N 34°W"
"12.345°N 123.456°E"
...
I've been working on a simple geospatial library which can parse coordinate strings. It is called Geo, and is licensed under the LGPL.
The Coordinate class has a static Parse method, and a couple of static TryParse methods.