Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Is there any C# library which can convert the geometry field into set of google latlngs? I have stored a shapefile into SQLserver table. From Sqlserver i want to read the geometry field data and want to convert this geom data into set of google latlngs in my C# application. Finally i want to save these google latlngs into another table in SQLServer.

share|improve this question
1  
was the input shapefile in wgs84 coordinate space? I'm also assuming input shapefile was of point geometry type? Also, was Geometry or Geography type specified in SqlServer table? –  user890 Feb 2 '12 at 15:35
    
The shapefile is of type polygon and is in swreff99_1800 coordinate space. yes,Geometry type is specified in Sqlserver table. Can u guide me any suitable C# library for the conversion. –  user1899 Feb 6 '12 at 13:23

1 Answer 1

up vote 1 down vote accepted

What about SQL Server Spatial Tools? You can incorporate it into SQL calls or use it in .NET code as well. The SqlProjection class might work for this. From the sample projection_example.sql in the source .zip:

-- Project point and linestring using Albers Equal Area projection
declare @albers Projection
set @albers = Projection::AlbersEqualArea(0, 0, 0, 60)

select @albers.Project('POINT (45 30)').ToString()
select @albers.Unproject(@albers.Project('LINESTRING (10 0, 10 10)')).ToString()
select @albers.ToString()

Also, look at this post on the SQL Server Spatial Tools discussions site, here is some code from that post:

--CREATE A GEOGRAPHIC POINT IN WGS84 LONGITUDE, LATITUDE COORDINATES
DECLARE @point GEOGRAPHY;
SET @point = GEOGRAPHY::STGeomFromText('POINT(5 52)',4326);

--PROJECT THE GEOGRAPHIC POINT TO A UNIT SPHERE MERCATOR PROJECTION
DECLARE @point_mercator GEOMETRY;
DECLARE @mercator Projection;
SET @mercator = Projection::Mercator(0) -- Initialize projection (0 = Longitude of Central Meridian)
SET @point_mercator = @mercator.Project(@point) -- Perform the projection
SELECT @point_mercator.STAsText() UNIT_SPHERE_MERCATOR
--UNIT_SPHERE_MERCATOR
--POINT (0.087266462599716474 1.0661617106056684)

--SCALE THE PROJECTED COORDINATES FROM THE UNIT SPHERE TO THE WGS84 SPHERE
DECLARE @point_mercator_wgs84 GEOMETRY;
DECLARE @a FLOAT;
SET @a = 6378137 -- Spherical Mercator Radius in meters
SET @point_mercator_wgs84 = AffineTransform::Scale(@a, @a).Apply(@point_mercator) -- perform the scaling operation
SELECT @point_mercator_wgs84.STAsText() AS WGS84_MERCATOR
--WGS84_MERCATOR
--POINT (556597.45396636787 6800125.4543973068)

To get the new transformed points to another table, you can do that with a SQL call. Actually, you could probably do all of what you need to do in one stored procedure using the SqlProjection class.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.