Converting geometry field into set of google latlng - sql-server

For storing Geospatial data, Geometry field is used in SQL server or Oracle Spatial. I want to know is there any way where we can convert this geometry field into set of latitudes and longitudes.

I'm assuming that the data in your geometry column is expressed using a projected coordinate reference system? If so, you'll have to unproject and/or transform it into the appropriate geographic coordinate reference system first. For Google Maps, this needs to be EPSG:4326 (WGS84)
Simply converting between the geometry and geography columns via WKT or WKB as suggested by paulH will not change the type of coordinates in which your data is expressed, and SQL Server provides no in-built transformation functions. Instead, you must make use of a third-party library such as Proj.NET (http://projnet.codeplex.com) which provides both projection and datum transformation functions using 7-parameter Helmert transforms. It's relatively easy to import this library and then create a SQLCLR procedure based on it to convert data between different SRIDs.
Once you've got a column of geography coordinate data in the correct SRID, you can select the latitude/longitude coordinate values of a given point using the Lat and Long properties.

If you can convert the Geometry field to a Geography data type (this article has some examples of how to do that), then you can select GeographyValue.Lat and GeographyValue.Long.

Related

QGIS edit turning POLYGON into MULTISURFACE

I have a PostGIS table with POLYGONs that I need to do some cleanup editing on in QGIS. However even a simple edit like deleting a vertex is saving the result back as a MULTISURFACE.
I am using QGIS 3.16.
How do I instruct QGIS to use the simplest geometry type that can represent the edited polygon?
I just ran into this issue and found your question. I think what is happening is geom columns that are generic "geometry" types are forcing QGIS to guess and/or convert the edited geometry in these columns to multisurface - I still don't know why.
To get around this, I created a new column and forced it to be multipolygon type:
alter table schema.table_name
add geom_mult geometry (Multipolygon, 4326);
Then populate my old geom column of 'mixed' geometries into this new column using ST_Multi(geom) to convert them:
update
schema.table_name
set geom_mult = ST_Multi((ST_Dump(ST_Multi(geom))).geom);
From there, I went back into QGIS and added the new table_name.geom_mult to my project. I went through the exact same editing scenarios that were causing the conversion to multisurface, and it is not converting them anymore - the polygons are all staying multipolygon - this includes topological editing using 'reshape surface' tasks and creating new singlepart polygons (qgis/postgis is storing them automatically as multipart).
So now I'm going to drop my old geom column, create a new one of multipolygon type, and re-add my converted multipolygons to this new column using an UPDATE. All my applications that expect a column called geom work just fine. I can change my QGIS layer definition to use MultiPolygon instead of Polygon (or MultiSurface depending on how QGIS read it when you added the layer).
Also I'm doing all this using multipolygon instead of just polygon as I do indeed have multipolygon data in my table, in addition to singlepart polygons. No one (QGIS, PostGIS) seems to care if singlepart polygons are stored as multipart features that I can tell.

Does snowflake support geometry data type which is used in sql server?

Does snowflake support geometry data type, which is used in SQL server? i only see geography data type in snowflake, whether same data from sql server to snowflake can be stored from geometry data type to geography data type column?
Snowflake supports only GEOGRAPHY data type. It's different than geometry data so you can not store them directly but you can try to convert it on SQL Server:
https://social.msdn.microsoft.com/Forums/en-US/a17a9320-8360-4497-942a-c3cbcec1d4cf/how-to-convert-geometry-to-geography-?forum=sqlspatial
Snowflake support GEOMETRY data type:
The GEOMETRY data type represents features in a planar (Euclidean, Cartesian) coordinate system.
The coordinates are represented as pairs of real numbers (x, y). Currently, only 2D coordinates are supported.
The units of the X and Y are determined by the spatial reference system (SRS) associated with the GEOMETRY object. The spatial reference system is identified by the spatial reference system identifier (SRID) number. Unless the SRID is provided when creating the GEOMETRY object or by calling ST_SETSRID, the SRID is 0.

EF Core SQL Coordinate type

I have Azure sql database with a table of objects. One of the columns is going to hold a coordinate (longitude and latitude) so I assume it is going to be the point type.
What C# Type do I use to represent this type and how do I show it in my model?
EF Core added Spatial data support in EF Core 2.2 through the NetTopolobySuite library. You need to add the Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite package to your project.
Points are represented by the Point class, preferably accessed through the IPoint interface. As the docs explain, the preferred way to create instances is through factory methods:
var geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326);
IPoint currentLocation = geometryFactory.CreatePoint(-122.121512, 47.6739882);

SQL SSRS Unable to determine the spatial data type in the specified dataset field: GEO

I need some help, I have a stored procedure(SP) that contains NO parameters in SSMS. The SP generates spatial data by joining 2 tables one table containing two fields needed for labelling purposes and the other from a table that containsthe GEO field.
This SP populates spatial data in SSMS which I can view and interact with. All seems well so far...
I then use SSRS to create a data source and a dataset of the said stored procedure. Following this I create a new .rdl and insert a map choosing SQL Server spatial query as the source then selecting the stored procedure dataset. Following this SSRS attempts to join the data and I then receive the error from the Microsoft SQL Server Report Designer:
Unable to determine the spatial data type in the specified dataset field: GEO
I have searched the the internet for answers already and none suit predominately because they all refer to parameters causing the issue however my query does not contain nor pass any. I have tried the geo field as both a geography and geometry datatype no avail.
Any help or advice would be great.
I have just been playing with a Heat Map in SSRS using SQL Jason's example (http://www.sqljason.com/2012/03/heat-maps-for-ssrs-using-map-control.html).
It looks like your data doesn't have enough points. According to Teo Lachev (http://prologika.com/CS/blogs/blog/archive/2009/08/30/heat-maps-as-reports.aspx):
SQL Server describes polygons in Well-Known Text (WKT) standard
sponsored by Open Geospatial Consortium. For instance, a polygon is
described as five (surprise) points on the coordinate system, as
shown below. The fifth point is the same as the first point.
The example format you gave only had four points. The first and last are the same so there seems to be a missing point or you are not graphing rectangles. It doesn't look like the Spatial Data supports any other shapes. The Map wizard only shows rectangles in the Wizard when creating the map.

SQL Server distance search

I have a Microsoft SQL Server database with a table of Locations. Each location has its address and latitude and longitude coordinates.
In my application, the user can input a zipcode and we return a list of close by locations.
This is my approach.
a) Using a zipcode DB I search the lat,lon for the zipcode (this is the center point).
b) I run a search like this
SELECT Position_ID, distance(pos_lon,pos_lat,zip_lon,zip_lat) dist
FROM Positions
ORDER BY dist
"distance" is a function that calculates the distance between two points.
The problem is that as my location DB increases the time to run these searches is starting to grow.
Is there a better approach?
If you're using SQL Server 2008, you probably want to look into the geography column type, the STDistance function and spatial indexes.
Spatial Indexing Overview
Geography Methods Supported by Spatial Indexes
How to: Create a Spatial Index
I would do a calculation of the box surrounding your zip code at the specified distance to get the lat/lon values for the four corners. Then do a simple comparison of your position values to select those which fall inside the square. This way, you don't have to calculate the distance from your zip code to every point in your db for every search.
Which version of SQL server? If 2008 have a look at the spatial type.
http://www.microsoft.com/sqlserver/2008/en/us/spatial-data.aspx
EDIT: Also limiting that query with a where would probably help as you likely don't want to go to far in any particular direction.

Resources