Quantcast
Channel: SQL Server Spatial forum
Viewing all 364 articles
Browse latest View live

1 record per X mile Radius

$
0
0

My table setup.
--------------------------
lat (float)
lon (float)
location  (varchar)
GeoLocation (geography)

The GeoLocation column above is set as:
----------------------------------------
SET [GeoLocation] = geography::STPointFromText('POINT(' + CAST([lon] AS VARCHAR(20)) + ' ' + CAST([lat] AS VARCHAR(20)) + ')', 4326)


---------------------
My Current Query:
---------------------
SELECT * FROM TheTablename WHERE (lat BETWEEN 40.03497548644043 AND 43.78596734966379) AND (lon BETWEEN -74.2606614248359 AND -70.7450364248359)

Returns all records within the boundries of the Lat and Lon. Works great.
-------------------------------------
What I need to figure out is:
-------------------------------------
How do I modify the above query to get 1 record per 20 mile radius. It would be a plus if I could get the center Lat,Lon of that radius.

For example: If I run the above query, 1 get 500 records back. I want to group them on the SQL server by 1 record per 20 mile radius. I would think it is possible to do this with the GeoLocation column but I just don't know how.

Any help is appreciated.

Thanks


import kml to sql server 2008

$
0
0

 

How to import KML file to sql server 2008

 

get Spatial image

$
0
0

Dears,I have simple question, i need to get the image that created from spatial result.

ex: i need to send mail with the (ex. "PIE" chart) from sql statement... so if you have any idea or suggestion about the i'll be thankful.

Split a complex LINESTRING & calculate distance

$
0
0

Hi

(using MS SQL 2008 R2)

Would it be possible to split a complex LINESTRING at a known intersection point on the linestring & then calculate distance on the half that contain the original starting point of the linestring.

Basically something similar to the "LocateAlongGeom" functionality in the CodePlex "sqlspatialtools" project, but slightly different that I know the point, but want to know the distance. (They know the distance and calculate the point)

 Much appreciated,

g

Latitude values must be between -90 and 90 degrees.

$
0
0

Hi All:

I was using GEOGRAPHY::STPointFromText and ran into the following problem:

A .NET Framework error occurred during execution of user-defined routine or aggregate "geography": 
System.FormatException: 24201: Latitude values must be between -90 and 90 degrees.

The solution was to use:

GEOGRAPHY::Point(46.3491096496582, -92.198318481445312, 4326)
Hope this helps.

Phil


P.Huhn

Get the bounding box from a DbGeography MULTIPOINT?

$
0
0

Sorry if the question is not 100% related to SQL Server itself. But I thought it matches the topic close enough to post it here.

I'm using Entity Framework in my ASP.NET Web API project. While creating my POCOs I receive LatLngBounds from the browser client (Google Maps API).

I create a DbGeography (MULTIPOINT) instance from these incoming coordinates that represents my two points to re-create a rectangle.

Now I need the bounding box (polygon) of this MULTIPOINT construct. After some research I thought the STEnvelope function from the SqlGeometry assembly might help on this as I can not find a way to do this with the DbGeography type. Everything looks fine in the code until I try so save the object.

Please see the gist [1] for example code an the error message from EF. See gist [2] for the generated SQL from EF.

Does it make sense to try it this way, or am I missing something important here and there's a much easier way?

[1] gist 1
[2] gist 2


Calculate distance between point and nearest point intersecting an area

$
0
0

Hi,

I am trying to find a way to get the distance between the start of a line and the point where that line intersects an area.

I am using the geography data type and SQL 2008R2

I have found various ways of achieving this in SQL2012 but none in 2008R2.

Can someone help?

Thanks,

Lucas


Querying points within a radius of point x

$
0
0

Hi,

Complete beginner to this and am keen to learn. Could someone to get me started (I've tried googling but really didnt help), explain what SQL query i would need to write to find a list of records which contain Geography points within a 1 mile circle of point X?

 

Thanks,

Matt


Spatial Data not returning a map in SSMS Standard 10.0 SP3

$
0
0

Hello All,

      I loaded the Tiger data the Microsoft makes available as sql files to be loaded into
SQL Server 2008. What I find strange is in the examples, when you query spatial data you get back a map with the points on the map plotted. When I query spatial data I get no spatial tab. I looked around figuring it was just a setting I was missing in SSMS, I didn't see anything, is this an Enterprise only feature like partitioning?

Regards,

Bryan

Calculating the midpoint in a line segment

$
0
0

Hello All,

I need to calculate the mid point of a line segment. Right now I calculated the intersected portion of a line with facility like this, PS is the pipeline table and fc is the facility table.

ps.gmlocation.STIntersection(fc.gmlocation)as PLIntersection

Now, How to calculate the midpoint of PLIntersection?

Any suggestions would greatly help.

Thanks

how to make rectangle using latitude and longitude values

$
0
0
how to make rectangle using latitude and longitude values

SqlGeometryBuilder AddCircularArc mistake in library?

$
0
0

The SqlGeometryBuilder.AddCircularArc method takes the start and end points of the arc as parameters.

I don't see how this can calculate and arc without a bulge value, radius or midpoint.

I can see how the SqlGeographyBuilder does this as it uses longitude and latitude so will have a curved surface built in. 

The documentation and intellisense for both builders mentions longitude and latitude but SqlGeometry does not have a surface like geography does so I was wondering if there is a mistake here in the library.

Separate a sqlgeometry(POLYGON) ,sometimes failed!

$
0
0

I want to separate a Polygon by a thin polygon,but when the thin polygon is too thin, fail to separate the big polygon.

why?

example:

--right examply: return multiPolygon,  separate right

select geometry::STGeomFromText('POLYGON ((0 0, 0 10000000, 10000000 10000000, 10000000 0,0 0))', 0).STDifference(
geometry::STGeomFromText('POLYGON ((0 0, 0 1, 10000000 10000000, 10000001 10000000,0 0))', 0)
).ToString()

--separate error
select geometry::STGeomFromText('POLYGON ((0 0, 0 10000000, 10000000 10000000, 10000000 0,0 0))', 0).STDifference(
geometry::STGeomFromText('LINESTRING  (-1 -1,1000000 11001000)', 0).STBuffer(0.02)
).ToString()

--return Polygon but not multiPolygon.

-- the thin polygon

select geometry::STGeomFromText('LINESTRING  (-1 -1,1000000 11001000)', 0).STBuffer(0.02).ToString()


look:
select geometry::STGeomFromText('POLYGON ((0 0, 0 10000000, 10000000 10000000, 10000000 0,0 0))', 0)
union all
select geometry::STGeomFromText('LINESTRING  (-1 -1,1000000 11001000)', 0).STBuffer(0.02)


(for authority,there is no image)


geography.STContains() or STIntersects() doesn't work

$
0
0

The following simple query doesn't work (i.e. it doesn't give the correct result).

DECLARE @g geography;
DECLARE @h geography;
SET @g = geography::STPolyFromText('POLYGON((-118.06852493286132 33.82165128304198, 
-118.01101837158202 33.85159452508453, 
-117.95025024414062 33.82550171608736, 
-117.96466979980468 33.77143718451128, 
-118.0480972290039 33.770723703910946, 
-118.06852493286132 33.82165128304198))', 4326);
SET @h = geography::STPointFromText('POINT(-118.04363403320312 33.823219998915484)', 4326);
SELECT @g.STContains(@h);

I have plotted all these points on a Bing map and they are valid. I also know that the point lies within the polygon. However, the Select statement above returns 0 (it should return 1). I have also used the STIntersects() function with the same result. I have also used the STIsValid() function to make sure that the input is valid. Can somebody help me resolve this issue?

I'm using SQL Server 2012 with compatibility level of 110. By the way, in my SQL Management Studio, I see red squiggle under "STContains". When I put my mouse over it, it says: "Could not find method 'STContains' for type 'Microsoft.SqlServer.Types.SqlGeography' in assembly 'Microsoft.SqlServer.Types' ".

Thanks.


DK

Trying to use spatial data retreived from SQL Azure in .NET with v11.0

$
0
0

I have a VS2010 web application that has various projects/layers behind it as references. I recently changed from v10 to v11 for my Microsoft.SQLServer.Types (using geography types) because a new version of a third party mapping tool I am using requires this version. I am getting the following exception in my data layer when I try to retreive some geogprahy data and pass to a variable. I can not find anything left in my projects referencing v10. I am using SQL Azure for my database. I found the Type System Version setting in the connection string and tried changing this to 2012, but this did not help. When I debug locally I get the exception upon access of the geography data. In Azure, it is looking for version 10.0 and can't find it so it just fails at the reference level. Does anyone know what I can do to resolve this issue?

exception occurs @ 

Dim geoExtent As Microsoft.SqlServer.Types.SqlGeography = dtAP.Rows(0).Item("IM_Extent")

[A]Microsoft.SqlServer.Types.SqlGeography cannot be cast to [B]Microsoft.SqlServer.Types.SqlGeography. Type A originates from 'Microsoft.SqlServer.Types, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' in the context 'Default' at location 'C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Types\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Types.dll'. Type B originates from 'Microsoft.SqlServer.Types, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' in the context 'Default' at location 'C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Types\11.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Types.dll'.


SQL Server spatial types redistributable

$
0
0

Hi,

I know this question has been previously asked here:

http://social.msdn.microsoft.com/Forums/sqlserver/en-US/174a3f81-60be-4da2-9a12-ab81d91c4cd9/are-the-spatial-dlls-redistributable

but I don't think there was a satisfactory answer and the thread was subsequently hijacked with unrelated problems. Does anyone have an up to date answer? Can I redistribute the following dll's with my software?

Microsoft.SqlServer.Types.dll

SQLServerSpatial.dll 

Thanks

How to find intersections with multiple shapes

$
0
0

Before I start, my disclaimer is that I am new to the spatial data types.

I have a table containing lat and long. I have figured out how to draw a 2 mile (3218.69 meter) buffer (circle) around each point and find intersections when two of these shapes touch. I need to figure out how to find when n shapes overlap. I need to find which rows overlap.

Here is my current code:

                              

DROP TABLE #GeoTable
CREATE TABLE #GeoTable (
GeoID INT NOT NULL IDENTITY(1,1) PRIMARY KEY,
Points geography NOT NULL)

INSERT INTO #GeoTable
        (  Points )
VALUES
        ( 
           geography::Point(47.6500, -122.3500, 4326)  -- Points - geography
          )

INSERT INTO #GeoTable
        (  Points )
VALUES
        ( 
           geography::Point(47.6800, -122.3500, 4326)  -- Points - geography
          )

INSERT INTO #GeoTable
        (  Points )
VALUES
        ( 
           geography::Point(47.6300, -122.3500, 4326)  -- Points - geography
          )

INSERT INTO #GeoTable
        (  Points )
VALUES
        ( 
           geography::Point(47.6300, -121.3500, 4326)  -- Points - geography
          );

-- I would like to get all of the intersecting rows: (Set 1,2; set 1,3; set 2,3; set 1,2,3):

WITH cte_UniqueRows AS (SELECT a.GeoID
FROM #GeoTable a
INNER JOIN #GeoTable b ON b.GeoID <> a.GeoID AND
a.Points.STBuffer(3218.69).STIntersects(b.Points.STBuffer(3218.69)) = 1
GROUP BY a.GeoID)
SELECT a.Points.STBuffer(3218.69)
FROM cte_UniqueRows ur INNER JOIN #GeoTable a ON ur.GeoID = a.GeoID

-- This will give me the 3 rows, but not if multiple rows intersect. (see spatial data in result set).

Thanks,

Rob

sp_helpindex does not show spatial indexes?

$
0
0

Is there no system SP like sp_helpindex that shows details for spatial indexes in a friendly way?

(newbie on spatial features here!)

SQL 2008 R2.

Thanks,

Josh

ps - I see you can select from sys.spatial_indexes but that does not list columns, etc.


32/64 bit problems using spatial queries on Azure

$
0
0

I have a WCF application/service that I host in Windows Azure. I alos am using SQL azure for my database. I have various spatial columns in my database and various stored procedures and text based queries with spatial data passed as WKB with type of VARBINARY that I call from .NET. I also have a few that I pass the parameters directly as GEOGRAPHY type. 

So I recently upgraded to VS2012 and .NET 4.5, and along with this upgraded my Azure instances to Server 2012. Since then I am getting an error when passing geography type parameters to text based queries from .NET in Azure. Everything works as expected on my dev machine. Please note that I only get the error when the query is text based and the same parameter can be passed to an sp without issue. I will provide some code below to illustrate this. 

The error I am getting is ''An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)",''

I understand that this is related to a problem calling a 32 bit dll. I found some kbs that suggest changing my target cpu to x86, but this seems like the wrong thing to do just to get this function to work. I could also write sps for all of my spatial functions, but I am really curious why this is happening with text based queries and not stored procedures at this point. 

Any insight on this issue is greatly appreciated. Code sample below:

Both functions include the following:

            Dim param As New SqlClient.SqlParameter
            param.ParameterName = "@geo"
            param.Value = Location
            param.UdtTypeName = "GEOGRAPHY"
            Command.Parameters.Add(param)

sp based query (works normally):

                Dim dtMaps As DataTable = FillDT("LPE_IM_GetNearby", CommandType.StoredProcedure)

text based query (returns incorrect format exception):

            Dim sCMD As String = "SELECT IM_ID, IM_Extent FROM LPE_IndoorMaps WHERE IM_Extent.STIntersects(@geo) = 1"


with Geo points (Longitude,Latitude). I need to connect the perimeter

$
0
0

i am developing KML file in Google Earth. with Geo points  (Longitude,Latitude). I need to connect the perimeter (Border Points) in a given space. Help me out. 

I tried using SQL Query for polygon but was unable to capture the end points and form a perimeter.

Thanks in Advance

Viewing all 364 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>