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

Geography SRIDs in a Geometry column?

$
0
0

I've recently used ArcCatalog to load a shapefile into SQL Server Express 2012.  The shapefile data was in NAD83, a geographic coordinate system with SRID 4269 in SQL Server.  I forgot to set the data type in the import wizard though, and the data was imported into SQL Server as a "Geometry" column.  The weird thing is that every record was imported with an SRID of 4269.  How is it possible to have a Geographic SRID stored in a Geometry column?  I think this one is for Alistair :)

Thanks,

Spatial Cowboy


How to pick the right Points to draw the Polygon

$
0
0

Hi,

I need to draw a polygon with the Latitude and Longitude Points. I am getting all the points from SQL Server 2008 from the Table. How to pick the Border Points to draw polygon.  Is there any method to pick the outer Border points to draw polygon. Thank's in Advance.

 

Thanks and Regards

Parthiban. R

How to translate addresses in bulk into Geography columns on my local machine?

$
0
0
I have addresses that I want to translate from addresses (varchar) into one Spatial/Geography column in SSRS 2008 R2.  But I want to do this in bulk since I have many addresses to translate and I want to do it on my local machine since this is HIPAA information.  How can I do this?  All of the geocode websites I've searched so far all require me to upload my records to their websites.  And doesn't web services require me to send this information over the internet?

Ryan D

Geospatial index on Partitioned table

$
0
0

I have a large table that includes a geospatial field called "Position".  I want to partition this table since it grows by 2 million rows per day.  I have 1 clustered primary index (Id) and 2 non clustered indexes, all aligned properly with the partition scheme so I can quickly "switch" out the old data.  So far the partitioning tests have worked great and I'm getting the results I expected.

I then defined the geospatial index and it doesn't seem to support partitioning.  Without an aligned index, I won't be able to "switch" out old data.  The online reference says...

ON filegroup_name

which implies that it is supported but I get a syntax error...

create SPATIAL INDEX SPATIAL_Reports on Reports
(
  Position
)
using GEOMETRY_GRID with
(
  BOUNDING_BOX = (-180, -90, 180, 90),
  GRIDS = (LEVEL_1 = MEDIUM, LEVEL_2 = MEDIUM, LEVEL_3 = MEDIUM, LEVEL_4 = MEDIUM),
  CELLS_PER_OBJECT = 16,
  PAD_INDEX = OFF,
  SORT_IN_TEMPDB = OFF,
  DROP_EXISTING = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON
)
on psReports ([ReportDate]);

... near [ReportDate]. 

This is the same syntax that I used to define the aligned non clustered index using the partition scheme psReports for the other 2 indexes.  Is my syntax really wrong or are partitioned geospatial indexes not supported in SQL Server 2008?

A concern with "geography::STLineFromText" in SQL Server 2008 R2: the function produces "The specified input does not represent a valid geography instance." for certain line strings

$
0
0

We have two select statements using "geography::STLineFromText" with almost the same input.

The only difference is in the last point of the line string passed in.

The question is: Why the first query fails when the second does not?

The first query (FAILS):

select geography::STLineFromText('LINESTRING(93.599998 13.2,93.599998 13.21,93.599998 13.19,93.599998 13.17,93.599998 13.42,93.68 13.88,93.790001 14.38,93.970001 14.89,94.010002 15.23,94.0 15.45,94.0 15.64,94.080002 15.76,94.18 15.95,94.360001 16.139999,94.480003 16.34,94.57 16.530001
,94.639999 16.700001)',4326)
--,94.64 16.7)',4326)
union all
select geography::Point(16.700001,94.639999,4326)

The second query (SUCCEEDS):

select geography::STLineFromText('LINESTRING(93.599998 13.2,93.599998 13.21,93.599998 13.19,93.599998 13.17,93.599998 13.42,93.68 13.88,93.790001 14.38,93.970001 14.89,94.010002 15.23,94.0 15.45,94.0 15.64,94.080002 15.76,94.18 15.95,94.360001 16.139999,94.480003 16.34,94.57 16.530001
,94.64 16.7)',4326)
--,94.639999 16.700001)',4326)
union all
select geography::Point(16.700001,94.639999,4326)

We tested the queries in SQL Server 2008 r2 and got the following error

"Msg 6522, Level 16, State 1, Line 1
A .NET Framework error occurred during execution of user-defined routine or aggregate "geography": 
System.ArgumentException: 24200: The specified input does not represent a valid geography instance.
System.ArgumentException: 
   at Microsoft.SqlServer.Types.SqlGeography.ConstructGeographyFromUserInput(GeoData g, Int32 srid)
   at Microsoft.SqlServer.Types.SqlGeography.GeographyFromText(OpenGisType type, SqlChars taggedText, Int32 srid)

"

Another sample query with the similar issue is:

select geography::STLineFromText('LINESTRING(
66.699996948242188000 13.800000190734863000
,66.699996948242188000 13.810000419616699000
,66.699996948242188000 13.789999961853027000
,66.699996948242188000 13.770000457763672000
,66.709999084472656000 14.010000228881836000
,66.790000915527344000 14.399999618530273000
,66.809997558593750000 14.739999771118164000
,66.809997558593750000 15.109999656677246000
,66.739997863769531000 15.489999771118164000
,66.639999389648438000 15.810000419616699000
,66.470001220703125000 16.190000534057617000
,66.269996643066406000 16.590000152587891000
,65.919998168945313000 17.059999465942383000
,65.510002136230469000 17.489999771118164000
,65.099998474121094000 17.909999847412109000
,64.629997253417969000 18.309999465942383000
,63.990001678466797000 18.690000534057617000
,63.290000915527344000 18.940000534057617000
,62.549999237060547000 19.159999847412109000
,61.770000457763672000 19.360000610351563000
,61.209999084472656000 19.420000076293945000
,60.790000915527344000 19.489999771118164000
,60.409999847412109000 19.569999694824219000
,60.090000152587891000 19.659999847412109000
,59.709999084472656000 19.850000381469727000
,59.319999694824219000 20.120000839233398000
,58.909999847412109000 20.399999618530273000
,58.450000762939453000 20.620000839233398000
,58.069999694824219000 20.819999694824219000)',4326)

After just changing coordinates of the last point the query "starts" working

select geography::STLineFromText('LINESTRING(
66.699996948242188000 13.800000190734863000
,66.699996948242188000 13.810000419616699000
,66.699996948242188000 13.789999961853027000
,66.699996948242188000 13.770000457763672000
,66.709999084472656000 14.010000228881836000
,66.790000915527344000 14.399999618530273000
,66.809997558593750000 14.739999771118164000
,66.809997558593750000 15.109999656677246000
,66.739997863769531000 15.489999771118164000
,66.639999389648438000 15.810000419616699000
,66.470001220703125000 16.190000534057617000
,66.269996643066406000 16.590000152587891000
,65.919998168945313000 17.059999465942383000
,65.510002136230469000 17.489999771118164000
,65.099998474121094000 17.909999847412109000
,64.629997253417969000 18.309999465942383000
,63.990001678466797000 18.690000534057617000
,63.290000915527344000 18.940000534057617000
,62.549999237060547000 19.159999847412109000
,61.770000457763672000 19.360000610351563000
,61.209999084472656000 19.420000076293945000
,60.790000915527344000 19.489999771118164000
,60.409999847412109000 19.569999694824219000
,60.090000152587891000 19.659999847412109000
,59.709999084472656000 19.850000381469727000
,59.319999694824219000 20.120000839233398000
,58.909999847412109000 20.399999618530273000
,58.450000762939453000 20.620000839233398000
,58.069999 20.819999)',4326)

varchar(max) 2 GB ??????

$
0
0

I have various shapes in WKT, going into a varchar(max) column, but for some reason they are being truncated after about 1400 geometric nodes. It affects maybe 60+ records., out of a total of 12,000 imported. 

The entire txt import file itself was only 68MB (all 12,000)!

How on earth have I reached a 2gb txt max in a varchar(max) for 1 record/column. I tried adding text to the affected columns and got a truncation warning, so i know the problem lies w/in the db engine/schema (not an import issue). 

The craziest part is I get no truncation warning to the Destination Column, but it's definitely 'overloaded'.

Any Clues, 

thx

Spatio

Sql server:Spatial Index not use by query a view

$
0
0

Hi Guys,

I was working with SQL Server 2008 Spatial Data, but I got a weird problem that the Spatial Index created for the tables doesn’t work when I query them with the view which is created based on this table. Following is the scripts I was using:

declare @Point geometry = geometry::STGeomFromText('POINT(937767.89433333278 -230404.864666667)', 102003)

select * from vw_StateForAddToMap 

where @Point.STWithin(shape)=1

go

I googled a lot and found an workaround at 

http://www.sqlskills.com/blogs/bobb/how-to-ensure-your-spatial-index-is-being-used/

 , but seems like this workaround just works when the queried geometry is point type, for polygons, like the script as following:

declare @Geometry2 geometry = geometry::STGeomFromText(

'POLYGON((-2079214.0399 1392052.275,-2079214.0399 -1156112.025,

1981332.1069 -1156112.025,1981332.1069 1392052.275,

-2079214.0399 1392052.275))', 102003)go

The spatial still doesn’t work. Anybody knows how to deal with this situation? Seems like the Microsoft doesn’t give a good instructions about this.

Any response will be appreciated.

How to solve this geography's problem in sqlserver2008 (shape file--> sqlserver2008)

$
0
0

I export one ARCGIS's shape file(wgs84) to sqlserver2008's geography table sucessfully.

Later I find both's lat/lon's value are different in shaper filIe and sqlserver2008's geography table

The same point is below both
shape file  110.68197631783 31.8551654808892 0 0
geography   110.97685242292907 31.64306831125624 0

1 I want to know the reason why both are different
2 how to sovle this problem so that their difference are less

 


SQL Server Zip Code Search Not Returning Requested Zipcode

$
0
0

I am using this code to return zip codes that are in a 20 mile radius of a specific zip code. Problem is it does not return the specified zipcode along with the ones in the radius. How can I get the zip code itself in the results?

SELECT h.*
FROM ZipCodes g
JOIN ZipCodes h on g.ZipCode <> h.ZipCode
AND g.ZipCode = '02116'
WHERE g.GeogCol1.STDistance(h.GeogCol1)<=(20 * 1609.344) 
ORDER By ZipCode

I followed an article on this for SQL Server 2008 which is what I am using. So I am not a super SQL guy to know all the possible issues with this so go gentle on me. ;)

STNumPoints

$
0
0

I am trying to return the number of points in Each Line Segment where the Table is a collection (rows) of unique Line Segments, using the method STNumPoints(). 

I have WKT and geometry data type for each instance (line segment), and would like to populate an entire column with the number of points in each  segment. 

I don't really have a clue how to use this function to generate the desired column, and have been unsuccessful with anything I've tried. 

Any clues????

thx

Spatio

Import LAS files to SQL SERVER 2008 and higher

$
0
0

Hi!

Im have worked with SQL SERVER for years (programmer and DBA) but never been in contact with spatial. At my new job at big autority working with land registration I've just got the answer from the programmers that the ONLY solution is POSTGIS and POSTGRESSQL for working with GIS-data (or Oracle if forced). Very well, we see about that. The game is a foot. They are perhaps right but I need to see it myself in a POC.

My first try, I have a LAS file (2GB) that I have converted to txt. Got the x y z and intensity and gps_time. Thats ~750K rows.

Q: Is it possible to import the LAS file directly and not convert it to txt. Shapefiles is out of question beacuse of its limitation of 2GB.

Q: Is it even possible to create a POINT CLOUD DATATYP as in Oracle and Postgres?

BR

Erber

Search for GoogleMaps viewport

$
0
0

Hello!

I have created the table for images and every image has its own Geo data (SQL GEOGRAPHY column). I'm trying to show these images on GoogleMaps so there is a web service that uses viewport (in fact 2 points NorthEast and SouthWest) from GoogleMaps and tries to search through images using this viewport. The problem is when I try to create polygon from viewport I get curved polygon and a lot of images are not shown on the map (all images below curved area).

But when GoogleMaps shows the map it looks like rectangle not a curved polygon. So I tried to figure out how to get rid of these curves and found Geometry polygon that looks exactly what I need but it doesn't work! When I try to use STContains it says Operand type clash: geography is incompatible with geometry.

SELECT * from Image where @geom.STContains(geo) = 1

Msg 206, Level 16, State 2, Line 19
Operand type clash: geography is incompatible with geometry

So my question is how can I get not-curved viewport and still be able to search through it? Or maybe the whole idea is totally wrong and I can't use SQL Geography with GoogleMaps?

Thanks!

spatial index not being used (NOT fixed by maxdop 1 or querytraceon 4199)

$
0
0

This is SQL Server 2012 (11.00.3381) running on Windows Server 2012.  It was 11.00.3000 but we tried the newest build to see if it affected anything).

The spatial index is never being used without a query hint.  As mentioned in the title, I have tried all the usual suspects.  In addition, I have exported the table to multiple other SQL Server 2012 instances (all on non Windows Server 2012 machines), and the same query on the table with an identical spatial index and the problem does not occur.

--
--this does not help
--dbcc traceon(4199, -1)
--DBCC FREEPROCCACHE

declare @geom geometry;

select top 1 
@geom=shape from  [gis].[PARCELS22]
order by DC;


SELECT top 100
p.[OBJECTID]
      , p.[Shape].STSrid
  FROM [gis].[PARCELS22] p
  --WITH (INDEX([S4_idx])) --uncommenting this fixes the problem
  where p.shape.Filter(@geom  ) = 1

   --this is already set on the instance but I tested the option below with no success
   -- option (maxdop 1)

To confirm the spatial index is not the culprit I compared the spatial index on the problem server with another server...

 declare @qs geometry;
select top 1 @qs=shape from parcels22;
exec sp_help_spatial_geometry_index 'dbo.parcels22', 's2_idx', 0, @qs;

The results for both are 100% identical.....

Total_Number_Of_ObjectCells_In_Level0_In_Index 3
Total_Number_Of_ObjectCells_In_Level1_In_Index 29
Total_Number_Of_ObjectCells_In_Level2_For_QuerySample2
Total_Number_Of_ObjectCells_In_Level2_In_Index 3495
Total_Number_Of_ObjectCells_In_Level3_For_QuerySample6
Total_Number_Of_ObjectCells_In_Level3_In_Index 76365
Total_Number_Of_ObjectCells_In_Level4_For_QuerySample7
Total_Number_Of_ObjectCells_In_Level4_In_Index 264946
Total_Number_Of_Interior_ObjectCells_In_Level2_In_Index23
Total_Number_Of_Interior_ObjectCells_In_Level3_In_Index1380
Total_Number_Of_Interior_ObjectCells_In_Level4_For_QuerySample2
Total_Number_Of_Interior_ObjectCells_In_Level4_In_Index28704
Total_Number_Of_Intersecting_ObjectCells_In_Level1_In_Index29
Total_Number_Of_Intersecting_ObjectCells_In_Level2_For_QuerySample2
Total_Number_Of_Intersecting_ObjectCells_In_Level2_In_Index3472
Total_Number_Of_Intersecting_ObjectCells_In_Level3_For_QuerySample6
Total_Number_Of_Intersecting_ObjectCells_In_Level3_In_Index74985
Total_Number_Of_Intersecting_ObjectCells_In_Level4_For_QuerySample5
Total_Number_Of_Intersecting_ObjectCells_In_Level4_In_Index236242
Total_Number_Of_Border_ObjectCells_In_Level0_In_Index3
Number_Of_Rows_Selected_By_Primary_Filter2
Number_Of_Rows_Selected_By_Internal_Filter1
Number_Of_Times_Secondary_Filter_Is_Called1
Number_Of_Rows_Output2
Percentage_Of_Rows_NotSelected_By_Primary_Filter 99.9940781097326
Percentage_Of_Primary_Filter_Rows_Selected_By_Internal_Filter50
Internal_Filter_Efficiency50
Primary_Filter_Efficiency100

The geometry column is srid 103562...

PROJCS["NAD_1983_CORS96_StatePlane_Virginia_South_FIPS_4502_Ft_US",GEOGCS["GCS_NAD_1983_CORS96",DATUM["D_NAD_1983_CORS96",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["False_Easting",11482916.66666666],PARAMETER["False_Northing",3280833.333333333],PARAMETER["Central_Meridian",-78.5],PARAMETER["Standard_Parallel_1",36.76666666666667],PARAMETER["Standard_Parallel_2",37.96666666666667],PARAMETER["Latitude_Of_Origin",36.33333333333334],UNIT["Foot_US",0.3048006096012192]]

This client is using ESRI 3rd party software, so query hints are not an option.   The only thing I can detect that is unique about this installation (from the dozens I have done internally and for clients) is the OS.

Help me Obi Wan.  I know you're out there.

 

ArcGIS to SQL Server projection problem

$
0
0

I have a dataset which uses the NAD_1927_UTM_Zone_17N coordinate system.

Due to the fact that the dataset locality still uses imperial measurements in its maps and surveying, the dataset has a linear unit measurement of one foot (0.3048 metres).  This in itself is fine, as all of the other datasets are the same and ArcMap understands that the linear unit is different and places the objects correctly in the 'real world'.

I've tried uploading this data to SQL Server (using the Shape2SQL tool) and, by the look of it, SQL Server is treating the (hidden) geometric measurements as metres - as is normally the case for this coordinate system.  As such, the objects are being placed in completely the wrong place on the map.

I'm not too sure where to start in order to account for this discrepancy, or whether it can be dealt with at all in SQL or prior to the load.

Does anyone have any recommendation?

SQL 2014 - Support for 3D for Geometry Objects?

$
0
0

Hi All,

with the Geometry support x,y,z for all Points, Lines and Polygons in SQL Server 2014?  I really need 3D.

gordon


Problem importing County Shape Files

$
0
0

I'm importing esri shape files from Harris County Texas to a SQL2012 database with ogr2ogr.   Harris County Texas provides esri shape files here:  http://pdata.hcad.org/GIS/index.html. I'm primarily interested in the parcels  (individually available here:  http://pdata.hcad.org/GIS/Parcels.exe).

I can execute this:

ogr2ogr -f "MSSQLSpatial" "MSSQL:server=localhost;database=GeoExperiments;trusted_connection=yes" "C:\Shapes\HCTx\Parcels.shp 

and it imports all 1.3+ Million rows into sql server promptly, but of course, it's simply importing GEOMETRY.  I want to import GEOGRAPHY.

If I execute this:

ogr2ogr -f "MSSQLSpatial" "MSSQL:server=localhost;database=GeoExperiments;trusted_connection=yes" "C:\Shapes\HCTx\Parcels.shp" -a_srs "EPSG:4269" -lco "GEOM_TYPE=geography" -lco "GEOM_NAME=geogr4269" -nln "HarrisCtyParcels" -progress

It results in this error:

ERROR 1: INSERT command for new feature failed. [Microsoft][ODBC SQL Server Driver][SQL Server]A .NET Framework error occurred during e

xecution of user-defined routine or aggregate "geography":
System.FormatException: 24201: Latitude values must be between -90 and 90 degrees.
System.FormatException:
   at Microsoft.SqlServer.Types.GeographyValidator.ValidatePoint(Double x, Double y, Nullable`1 z, Nullable`1 m)
   at Microsoft.SqlServer.Types.Validator.BeginFigure(Double x, Double y, Nullable`1 z, Nullable`1 m)
   at Microsoft.SqlServer.Types.Forw
ERROR 1: Terminating translation prematurely after failed
translation of layer Parcels (use -skipfailures to skip errors

I did look in the .prj file and went to the epsg-registry.org to find the EPSG code:

Code: EPSG::6588
Name: NAD83(2011) / Texas South Central (ftUS)

but since it's based on the regular 

"EPSG:4269" and since the 6588 is not in the sys.spatial_reference_systems table, I thought the 4269 code was likely the right one.  I would appreciate your help with that.  None the less, I've tried both codes and gotten the same results.

How do I fix the problem with the import?

Thanks much for your help!

Gay Spencer


New Top Support Solutions blog

$
0
0

Hello

As part of our efforts to keep our communities informed about the most relevant content that address the top questions that we are getting in out forums and other support channels we want to introduce the new “Top Solution Content” blog (http://blogs.technet.com/b/topsupportsolutions).

In this blog you will find up-to-date and valuable information about Microsoft top support solutions for several of our popular products in the Server and Tools portfolio. You can use the tags (http://blogs.technet.com/b/topsupportsolutions/archive/tags) to easily locate the product of your preference or visit the home page to see what’s going on for the different Microsoft Enterprise and developer products. As a blog you can also subscribe to post and comments using the RSS feeds.

We hope this will reduce time and effort when you are looking for relevant content. Enjoy it!

Thanks

Microsoft Support team


Elvis Long
TechNet Community Support

How to get timezone (offset) for a given Geography point?

$
0
0

Hi everybody...

Anyone knows how to obtain the time zone for any geography (lat, lng) point?

I have a GPS device that transmit lat, lng, and time in UTC, but i need to know the time offset of that coordinate using sql 2008.

I will appreciate any help. Thanks.


Bernardo Salazar

create a spatail table using a shape file (.shp) in SQL DB

$
0
0

Hi All,

I am trying to load shape file into a sql spatial table. A execution process task is used to run the ogr2ogr.exe program.

This is how the process tab looks like .

Executable : C:\gdal_ogr2ogr\bin\gdal\apps\ogr2ogr.exe

Argument :  -f MSSQLSpatial   MSSQL:server=SQL-ABC-DEV;database=MYSIMPLE_Dev;Trusted_Connection=True;\\mypath\files\shares\Data\www.mypage.htm\my_sample_file.shp

Success value : 1 (I am not sure why I need to change this value from 0 to 1.

For above settings, package runs fine. However the spatial table is not created always. It is created once in a while after switching Success value from 1 to 0 and 0 to 1 again. (After the spatial table is created, it is dropped using a execute sql statement). If I run this command SDKShell.bat file, it always works.

I am running this in VS 2012.I saw in an article that we need to convert shp file to csv before we load it into sql server.I even tried to convert shp to csv using execute sql task and ogr2ogr.exe. Still the package runs successfully after changing Success value from 0 to 1 but no csv file is created. If the success value is 0, it throws the following error.

[Execute Process Task] Error: In Executing "C:\gdal_ogr2ogr\bin\gdal\apps\ogr2ogr.exe" " -f CSV \\xxxxxxxxr.rdn\files\shares\xxx_Data\ImportData\www.xxxxxxx.hapepage.htm\xxxxxx\Watches\Warnings\myfile\CSV \\xxxxxxxxr.rdn\files\shares\xxx_Data\ImportData\www.xxxxxxx.hapepage.htm\xxxxxx\Watches\Warnings\myfiles\www.shp" at "", The process exit code was "1" while the expected was "0".

Could long file name be a problem too?

Thanks for your help in advance..


shamen

Cannot create a polygon using geography data type

$
0
0

I know about the single hemisphere limitation and that the lines of the  polygon cannot intersect by itself. But I dont understand what is wrong with the following.

 

DECLARE

 

@geog1 geography

SET

 

@geog1 =geography::STPolyFromText('POLYGON((-118.180972 34.738801,-118.147155 34.738801,-118.147155 34.731747,-118.180972 34.731747,-118.180972 34.738801,-118.180972 34.738801))',4269)

I checked the poloygon by using the following

select

 

geography::Parse('LINESTRING(-118.180972 34.738801,-118.147155 34.738801,-118.147155 34.731747,-118.180972 34.731747,-118.180972 34.738801,-118.180972 34.738801)')

But I could see a clear rectangle without any lines overlapping . Then what did I do wrongly? Can anyone help please....

 

 

 

Viewing all 364 articles
Browse latest View live


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