Acronym for Structured Query Language. A syntax for retrieving and manipulating data from a relational database.

learn more… | top users | synonyms

5
votes
2answers
8k views

'Select by attribute' using python in ArcMap 10

I need to select a feature using SQL before zooming to it in python. What I'm looking for are replacements for the commented lines in this code: import arcpy parcel_num = "123456" mxd = ...
5
votes
1answer
283 views

ogr2ogr selecting features by attributes

I am writing a shapefile after some processing; however, in the final step I need to do some selection by attributes from the the shapefile. I am using the command in a shell with the aim of using it ...
5
votes
5answers
3k views

How can one execute an SQL script in field calculator in ArcGIS 10?

I am trying to transfer over row data from a table to columns in a shapefile table. There is a common "SA" variable between the two (i.e. the study area number) but there is more than one land use ...
5
votes
2answers
974 views

Using an integer variable in where-clause in arcgis python script

I've seen some questions on this, but there seem to be many different answers... and none have seemed to work. I'm trying to include an integer variable in the SQL where-clause of a tool like this ...
5
votes
2answers
255 views

ArcSDE recently modified geometries

ArcSDE 10 with a MS SQL 2005 backend. I am trying to see the most recently modified geometries using SQL so that I can use it to update another GIS database running PostGIS. Has anyone tried this ...
5
votes
2answers
222 views

Selecting maximum Value based on other field using ArcMap?

I have problems with a SQL query. The table looks like this, it is a point feature class both in postgres and file geodatabase, I am working in ArcMap. name: elev_p HEIGHT AREAid 100 1 200 1 ...
5
votes
1answer
4k views

Arcpy cursors, WHERE clauses, and date/time fields

I'm having trouble making a selection of rows that meet certain date criteria using my arcpy.UpdateCursor(). I need to update records in a field in a geodatabase table with an ascending value based on ...
5
votes
1answer
359 views

How to filter points based on proximity while inserting into PostGIS?

I have a large amount of locations that need to be inserted to a PostGIS database. However, I'd like to aggregate these points so that if there's already a location, say nearer than a kilometer, then ...
5
votes
1answer
300 views

Postgres/postgis cursors

I have a road network with StreetName and min/max address ranges for each segment (ie- StreetName = 'Main St', Min = 100, Max = 199). I also have individual address points with similar information ...
5
votes
1answer
89 views

SQL “Case” statement when count(*) is 0

I am trying to write the following SQL command using case clause. with x as (select the_geom as geom from table1 where st_dwithin(the_geom, st_setsrid(st_makepoint(28.959495,41.019913), 4326), ...
5
votes
2answers
569 views

Change polygon “handedness” for SQL 2008

I have a few hundred shapes (polygons and multipolygons) each consisting of tens of thousands of points that I am trying to get into SQL 2008. Unfortunately, the shapes I have tried to import are ...
5
votes
2answers
1k views

Does SQL Server need extensions to do spatial?

Does SQL Server need extensions to do spatial like Oracle does? Just wondering if there will be extra costs for implementing a SQL Server backend to SDE. Thanks
5
votes
1answer
589 views

How to run custom queries on vector layers and display results?

Is there a way to display the result of a query in QGIS? For instance : To get the total number of inhabitants : SELECT SUM( inhabitants ) FROM countries To get the total density : SELECT ...
5
votes
2answers
1k views

How to export a PostGIS raster to PNG?

I have a raster which is split into 30 tiles and I want to dump them all into PNGs. I've read the documentation http://postgis.net/docs/RT_ST_AsPNG.html but still don't know how to dump it well. If ...
5
votes
2answers
389 views

Selecting POIs around specific buildings using PostGIS

The problem: I need to select, for each residential building in my table that has say at least 2 pharmacies and 2 education centers within a radius of 1km, all POIs (pharmacies, comercial centres, ...
5
votes
3answers
677 views

Sqlite, Python 2.7 and Spatialite

I am trying to spatially enable my sqlite database: import sqlite3 db = r'c:\temp\mydata.sqlite' conn = sqlite3.connect(db) conn.enable_load_extension(True) cur = conn.cursor() cur.execute(r"SELECT ...
5
votes
1answer
267 views

Is it possible that a good spatial index just cannot be made?

I have about 6 million rows with geography spatial features - they are all 1000 meter radius hexagons all over the US. There are a couple hundred thousand that would have been NULL, which I updated ...
5
votes
1answer
459 views

How to Comment Out Definition Queries

I use Definition Queries a lot in my daily GIS life, but one of the many things I've found annoying about ArcMap is the inability to comment out Definition Queries. I'd like to have this option as ...
5
votes
2answers
936 views

How to find the nearest land mark from a given longitude and latitude?

I have a table called osm_places with place_name geometry, place_type and many other info related to the city. My database system is PostGIS. My requirement is: Given a latitude and longitude ...
5
votes
2answers
69 views

How to select random adjacent census tract

I have set of census tracts spaced out across a city and I would like to randomly choose an adjacent census tract to explore nearby demographic data. I'm not sure if there is an easy process for ...
5
votes
2answers
788 views

How to fix pgRouting error “starting vertex not found”?

I've posted on here before about my battles with drivetime polygons and got some sensible suggestions back, so having Googled myself stupid over this I'm turning to you once again in the hope of a ...
5
votes
2answers
79 views

How to draw radius of a circular point buffer using PostGIS

I have generated circular buffers of points in a shapefile. The generated circles and points share a common ID/key, say pt_id. My question is Is it possible to use PostGIS to generate a third layer ...
4
votes
4answers
2k views

Updating 30 Shapefiles, adding attribute and populating based on data

I need to add an attribute to each shapefile attribute table in ArcMap, I was thinking to do it in SQL, but I'm not sure how to go about doing it since I'm very new to ArcMap. Can someone explain to ...
4
votes
3answers
510 views

How to create Where Clause from user input via Python list?

I am trying to perform a query based on values in a Python list. The where clause will then be used in an Update Cursor, so that the rows NOT equal to the values in the list will be deleted. This is ...
4
votes
3answers
4k views

ArcGIS - Create a join based on multiple fields

I have two feature classes in a File Geodatabase that I would like to join based on multiple fields. I've searched this site and Google and all I have come up with was to use the Make Query Table ...
4
votes
2answers
265 views

Which Geodatabase supports SQL and is easily portable?

I want to choose the geodatabase type, which could be: permits direct sql queries. easily portable, because the app would installed in one computer. I know that the personal geodatabase is a good ...
4
votes
2answers
999 views

What is the best approach to using IQueryFilter.WhereClause in ArcObjects?

What is your preferred / best approach to using IQueryFilter.WhereClause statements in ArcObjects (e.g. when selecting features by attributes)? You need to check the source type (shapefile / personal ...
4
votes
3answers
284 views

Maximum length of WHERE clause with IN statement

I need to get all features from feature class where their field value matches to input array. To achive this one may set IQueryFilter.WhereClause property similar to 'FIELD_NAME IN (array[0], ...
4
votes
1answer
329 views

SQL Server data modelling + spatial data = what book?

What recommended book can you provide about data modelling for geographical spatial data (geometry) in SQL server?
4
votes
2answers
920 views

Changing Buffer table geometry dynamically in PostGIS using plain SQL

I have two tables in PostGIS, a point and a point_buffer table. The point table has a buffer_distance field, with a default value say 200. Now I want to change the buffer table geometry whenever I ...
4
votes
2answers
653 views

SQL Syntax to extract (convert) Strings with Degrees Minutes to Decimal Degrees

I have a PostgreSQL/PostGIS database with a two string fields containing Lat and Long coordinates in degrees and decimal minutes, like this 45° 24.5' N 3° 43.01' E. How can I convert them into ...
4
votes
2answers
390 views

PostGIS stored procedures

I am wondering if there are open source applications that make extensive uses of the special functions (the ST_* stored procedures) provided by PostGIS? I found many apps that support storing map data ...
4
votes
1answer
2k views

STIntersects - Update field to give me count of points in polygon

I have a points layer (dbo.ptLayer) Around 1M points Spatial Geometry Type (dbo.ptLayer.geom) No spatial index just yet, but will create one once data gathering complete. I have a polygon layer ...
4
votes
1answer
779 views

Select by attribute expression invalid in python

I'm not sure how my expression is failing. Any ideas? inPoints = "points.shp" i = 0 arcpy.MakeFeatureLayer_management(inPoints, "pts") arcpy.SelectLayerByAttribute_management("pts", "NEW_SELECTION", ...
4
votes
2answers
803 views

Using a bounding polygon, instead of a bounding box

I've got a large set of LAT/LON coordinates. Up until now, when I needed to select out those that fell within a certain region, I'd just create a bounding box using some MINx, MAXx, MINy, MAXy values ...
4
votes
1answer
376 views

How to populate SQL options for parameter in ArcGIS 10 tool?

I'm trying to create a tool where individuals can select a variety of records using a SQL expression that is then passed to a calculation. I can add a parameter under the tool, and select SQL ...
4
votes
2answers
659 views

Calculate Field based on field value in a second table

I have a table in a MSSQL Server Enterprise SDE database. I need to join a table from a MS SQLExpress Workgroup SDE database and then calculate 11 fields in the Enterprise table based on values in ...
4
votes
3answers
529 views

How to select a number of rows based on current sort order

I would like to be able to select a certain number of rows from my attribute table based on their ordering and not their attributes. For example, if I sort by ObjectID, I then want to select the top ...
4
votes
1answer
2k views

Performing Geoprocessing SQL Queries in QGIS from a PostGIS Database

This may be a dumb question, but is there way to run a PostGIS geoprocessing SQL query in QGIS? Specifically, I am thinking of running SQLs such as ST_Union, ST_Split etc etc. I have tried the ...
4
votes
1answer
273 views

ogrinfo SQL GROUP BY Clause

Does ogrinfo support a GROUP BY clauses? I could not find any good documentation of all the SQL syntax features it supports. I tried the following: ogrinfo . -geom=no -sql 'SELECT lsad FROM ...
4
votes
2answers
531 views

Merge reversed linestring in correct order in postGIS

I want to merge linestring in the correct order in postGIS, but sometime they are reversed so something like this : select astext(linemerge(ST_union( ST_GeomFromText('LINESTRING(3 3, 2 2)'), ...
4
votes
3answers
992 views

How to automatically create 2D-point features from addresses in an SQL database

I currently have an SQL-Table which contains our buildings. I already added the table and now want to create features ( 2D-Points ) from that information. The biggest problem I have is that the ...
4
votes
2answers
401 views

how to cast integer to float in an ogrinfo sql statement?

I have a shapefile for which I would like to add the values in a column. As the sum exceed the capacity of an integer, I need to cast values to a float. I tried the following: ogrinfo -sql "SELECT ...
4
votes
3answers
781 views

Incorporating SQL Statements in Model Builder

I have a point data set where each point has a unique operator associated with it. I'd like to select by attribute = operator name and generate a new shapefile for each operator containing only the ...
4
votes
1answer
681 views

Spatialite SpatialSQL Query

I've been flummoxed by this query. I have a table of points, and a table of lines, and I am trying to return the point id and line id whenever the point is contained within a buffer of the line (i.e. ...
4
votes
1answer
444 views

Geodjango insert statement: psycopg2.IntegrityError: violates check constraint

Why is the following INSERT statement throwing this error? INSERT INTO domes_place (placeid, structidx, oscode) VALUES ('10', '1', 'POINT(51.121282945772 1.3138398501222)'); psycopg2.IntegrityError: ...
4
votes
2answers
1k views

Import large CSV file into PostGIS

I am trying to import CSV files into PostGIS. Following this post, I have created tables before. I found other suggestions saying that I can run the copy command. If I run this command: COPY table ...
4
votes
1answer
166 views

How to query nearest date in ArcGIS Server REST?

How to query nearest date (today) in ArcGIS Server REST? Table: ID NAME DATA 1 test 2013-06-01 13:00:00 2 test1 2013-06-01 16:00:00 3 test2 ...
4
votes
3answers
2k views

How to join two tables using date, time, lat and lon as common field?

I am sorry if the question is elementary but I did not find any clear discussion or guide to understand how to run a query in postgresql. So that a pointer to another website would be also useful. ...
4
votes
2answers
2k views

Publish SQL Views from Postgres/Postgis to Geoserver

I've trying and reading how to publish a Postgres/Postgis View in Geoserver. I know that I can create an SQL View in Geoserver, but I'd like to define the View in Postgres, not in Geoserver. Does ...