Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [psycopg2]

Psycopg is a popular PostgreSQL database adapter for the Python programming language

1
vote
0answers
36 views

QGIS 3 Python plugin psycopg2 Postgres Notify/Listen Live Connection

I'm developing a plugin for QGIS3 for my company, where my managers can allocate tasks to other users. I have programmed two tables within the python script, witch will be only visible according to ...
1
vote
0answers
84 views

ERROR 6: EPSG PCS/GCS code 102027 not found in EPSG support files

I am trying to insert spatial data from GeoJSON to PostgreSQL database and before it I am to reproject geom from EPSG:4326 to EPSG:102027. When working on Windows there were no problems with CRS, but ...
7
votes
0answers
143 views

Multithreaded DB connection for QGIS plugin

I am using QGIS 2.18.21 and PostgreSQL 9.6. on a Windows 8 machine. I am trying to do processing of a certain database task in the background, and I want the user to be able to continue to work in ...
0
votes
0answers
152 views

How to select all point inside polygon in PostGIS?

I have a table samplecol that contains (a sample): vessel_hash | status | station | speed | latitude | longitude | course | heading | timestamp | the_geom ...
0
votes
2answers
161 views

PostGIS & Python SQL Query formatting: Create Geometry only for entries that are not NULL

I think this is rather a formatting issue. I have a database with a geometry Column that sometimes contains points. Normally, it will be None/Null. When I format the SQL query in psychopg2 and python ...
0
votes
0answers
143 views

How to set the nodata of Clip raster in postgis to export as tif

I'm trying to crop a raster by polygon and export as TIFF data. The problem is how to set the nodata around the polygon in the raster using psycopg2 in python, because the default value is -3....
1
vote
1answer
306 views

python psycopg2 insert table into postgis: geometry requires more points

I have a feature class of 20k records. trying to import it into postgis using arcpy and psycogp2. I have a pretty basic script cur.execute('''drop table if exists developed_lands.daysemtric_test''') ...
2
votes
1answer
300 views

psycopg2 : Query Postgis Function

I want to do Query : SELECT ST_AsText(ST_MakePoint(-7.83753572095, 110.354612964)) ; my python code = import psycopg2 conn = psycopg2.connect(dbname = 'gis02', host= '127.0.0.1', user = 'gis2user',...
2
votes
2answers
156 views

Automatically set PostGIS/QGIS style to a layer

I have a plugin for my users which allow them to create a spatial view for different layers. I have define a set of styles fitting the display I want to give. I would like to define these styles to ...
0
votes
0answers
71 views

Difficulty finding Intersection using PostGIS?

When I run my code, each time the memory reaches its limit and the system gets stuck. There is no output. This is my code. I am using PostGIS from psycopg2. iin="""WITH a AS ( SELECT * FROM ...
-1
votes
1answer
197 views

Error in creating table (Postgis)

I am trying to write a python function to run PostGIS query: import psycopg2 connection = psycopg2.connect(database="postgresdb",user="postgres", password="pass123") print "Opened database ...
4
votes
1answer
482 views

JSON rings data to PostGIS

Pulling data from a arcgis web query and using python/psycopg2 to insert it into postgreSQL. Here is one of the geometry attributes js = json.dumps(i['geometry']['rings']) this line prints [[[...
1
vote
1answer
180 views

Arcpy to PostgreSQL using psycopg2 with MULTIPOLYGON using WKT

I am trying to create a MULTIPOLGYON in PostgreSQL from WKT format using arcpy.da module and psycopg2. I have had success creating point and multi point shapes this way however I cannot seem to get ...
2
votes
2answers
79 views

Preparing geometry for psycopg2 using ArcPy without SHAPE@WKT?

Trying to print out a polygon shapefile in WKT format in a standalone script. I am using ArcGIS 10.1 and use the da modules all the time. I have seen this post Converting geometry to WKT using ArcPy? ...
2
votes
2answers
368 views

How to pass parameters to PostGIS queries containing geography type in Python using psycopg2

I have the following example (adapted from the PostGIS manual (version 2.2): CREATE TABLE global_points ( id SERIAL PRIMARY KEY, name VARCHAR(64), location GEOGRAPHY(POINT,4326) ); ...
1
vote
1answer
80 views

How do I import OS Sites Layer into QGIS/PostGIS?

I've found the OS Translator II plugin which works perfectly for the Topology Layers, but it doesn't have an option to import OS Sites Layers. How can I import this product into QGIS/PostGIS? I've ...
0
votes
1answer
41 views

PostGIS to Find Dupes and Segregate Geometric Dupes from Originals?

I've written some code in Python and PostGIS to find duplicate geometric features within the same feature layer. That part is a success. The problem I have is the dupes as well as the original ...
0
votes
1answer
779 views

Insert points to PostGIS using a function

I am trying to insert points geometry into PostGIS database. Well I tried to use a function just to read point coordinates and attributes and save them in a table in PostGIS. It works for attributes ...
4
votes
1answer
366 views

QgsDataSourceuRI and left outer join

I'm trying to load data from different tables using left outer joins into a QgsVectorLayer. The approach I'm following so far is the one from the developers cookbook here. The underlying database is ...
0
votes
1answer
949 views

Python to Postgres insert Geometry syntax

Having trouble creating geom columns and inserting geometry lat lng values into postgres table Is my syntax correct in creating the point geometry fields? st_makepoint is the point constructor. when ...
1
vote
1answer
1k views

Create Table with postGIS geometry in Python

I'm creating the following table with a postGIS geometry column in python but get an error psycopg2.ProgrammingError: type "geometry" does not exist What should I use to be able to use postGIS in ...
2
votes
2answers
445 views

Using zoo-project WPS service in QGIS WPS-Client

I've created a python wps service in the zoo-project framework, which is used to calculate a Line of Sight based in on a start point, an end point and a start point height. The service works fine if i ...
4
votes
1answer
254 views

Tweepy Psycopg2 creating points, coordinate system SRID confusing

I am using Tweepy and Psycopg2 to extract tweets and input them in a PostgreSQL table. When I try to insert the point of the tweet I succeed in creating a point in the geom column I create. I however ...
2
votes
2answers
180 views

Why does psycopg2 “SELECT ST_AsBinary(geom)” return “<read-only buffer…>”?

I'm trying to retrieve polygons out of a postgresql database and I'm running into several problems. First, I've been able to get ST_AsText(geom) to work in conjunction with arcpy.FromWKT(), but the ...
0
votes
1answer
431 views

Can't execute a simple psycopg2 script twice when running from ArcGIS Desktop as a script tool

I'm building a geoprocessing service that queries an SDE database (running on postgres) and returns results. I do a lot of development by calling the script from a toolbox in ArcGIS desktop 10.3. ...
2
votes
2answers
494 views

PostGIS operations extremely slow when called in a script

OK, I am aware that this is rather vague, but unfortunately I was not able not reproduce my problem in simplified code. I am running a series of functions within another function (main()). All ...
1
vote
1answer
136 views

String quoting issues with sql using ST_PointFromText in psycopg2

I've been banging my head against this for a while, and am seeking some insight into what I'm doing wrong. I have the following snippet of code: params = [PlaneRep.hex, PlaneRep.squawk, PlaneRep....
0
votes
1answer
2k views

Query table names

I want to query a table in my PostGIS table named Seg_060_2009 using psycopg2 and can't seem to get my query to execute. The query will execute if I name the table layer. Are there restrictions on ...
2
votes
2answers
3k views

Import shapefiles into PostGIS using Python with psycopg2

I want to import shapefiles to PostGIS using Python with arcpy & psycopg2 to connect to PostGIS. I don't want to use the existing shapefile loader nor ogr, just write my own import tool. My steps ...
0
votes
0answers
1k views

ST_MakePoint returns an error when using Python

I am trying to use ST_Point or ST_MakePoint to create points from a table of latitude and longitudes coordinates. However I am consistently getting an error even when trying the examples. For example ...
1
vote
1answer
849 views

Get a point value with psycopg2 and PPyGIS

I'm trying to setup a basic working postgis setup with python ppygis package. >>> import psycopg2 >>> import ppygis >>> connection = psycopg2.connect(database='spre', user='...
10
votes
2answers
2k views

Downloading raster data into python from postgis using psycopg2

I have raster data in a postgres table that I want to get into python as a numpy array. I am using psycopg2 to connect to the db. I am able to download the data but it comes back as a string (probably ...
1
vote
0answers
2k views

Generate random points in polygon. Algorithm question

i created a Random Point Generator in python using the algorithm described here by @whuber. The algorithm is implemented using Shapely, PostGIS and psycopg2. To boost performance pythons ...
2
votes
1answer
266 views

Computing intersections for each geometry in a table

I have a table with many Linestrings and for each of these Linestrings I need to figure out which other Linestrings, from the same table, intersect with it. If I recall correctly this gives me a ...
11
votes
2answers
12k views

Insert a Point into PostGIS using Python

What is the right way to insert a Point to a PostGIS database using Python?
0
votes
0answers
3k views

Postgres SSL SYSCALL error: EOF detected with python and psycopg

Using psycopg2 package with python 2.7 I keep getting the titled error: psycopg2.DatabaseError: SSL SYSCALL error: EOF detected It only occurs when I add a WHERE column LIKE ''%X%'' clause to my ...
1
vote
1answer
1k views

Import raster into PostGIS using Python

I am trying to import information from a Bathymetric Attributed Grid (BAG) file into PostGIS using Python and psycopg2. I'm working, for now, on a Windows box with pre-compiled packages, so I don't ...
1
vote
4answers
2k views

Get srid from a shapefile using ogr

I'm writing a script to import shp to postgis, using python, osgeo and psycopg2 ( see my previous question: Import shp to Postgis using Python and ogr ) I'd know if there is a way to get by osgeo ...
0
votes
2answers
13k views

How to save results of postgresql to csv/excel file using psycopg2?

I use driving_distance in postgresql to find distances between all nodes, and here's my python script in pyscripter, import sys #set up psycopg2 environment import psycopg2 #driving_distance module ...
0
votes
1answer
13k views

Use psycopg2 to do loop in postgresql

I use postgresql 8.4 to route a river network, and I want to use psycopg2 to loop through all data points in my river network. #set up python and postgresql connection import psycopg2 query = """ ...
1
vote
1answer
9k views

How to execute sql lines in postgresql using python?

I use postgresql 8.4 to route a river network, the following is my code typed in pgAdmin and the result is fine, select * from driving_distance ('select gid as id, start_id::int4 as source, end_id::...
7
votes
3answers
9k views

PostGIS: parse geometry wkb with OGR

I'm trying to pull a LineString geometry out of PostGIS and parse it with OGR (python bindinds). from osgeo import ogr import psycopg2 connection = psycopg2.connect("...") cursor = connection.cursor(...
2
votes
1answer
846 views

Transferring data between spatial databases

I would like transfer spatial data from PostGIS to Oracle Spatial. I want to use Python's modules psycopg2 and cx_oracle. Transfer Oracle > PostGIS is OK, but in opposite version I have problem with a ...
1
vote
1answer
929 views

Can't install psycopg2 on Mac 10.8.2

I know there Have been a lot of similar questions asked but none address this issue as I far as I can tell. When I am trying to install the sextante plugin, or run PostGIS Manager in QGIS I receive ...
2
votes
1answer
358 views

How to configure and install psycogpg2 - beginner?

I need to install psycogpg2 for working with 'django'. I read the instructions but I don't understand whether to run the commands in command prompt or in Python command line. I am not used to the GUI ...
1
vote
0answers
575 views

Why is not ST_GeomFromEWKB() working?

The following SQL is working fine from the terminal: SELECT MIN(ST_Distance( ST_Transform(ST_GeomFromText('POINT(-3.163916 55.926528)',4326),32630), ST_Transform(ST_Boundary(ST_GeomFromEWKB(...