I have a spatialite database file containing buildings within a country as multipolygons. While trying to use QGIS to delete these duplicate features, QGIS keeps on crashing due to the millions of buildings within the layer. So I am trying to find an command line solution using ogr2ogr but cannot find any info. What would be the syntax to do such a task?
120403
I have shapefile with lines, some of them are perfectly overlaps - duplicate, although each one have unique id etc.   When I view the file in QGIS I see they overlap. When I convert the file with ogr2osm to osm XML &amp; import to JOSM, and running validation I also get warning of duplicate ways (the lines converted to ways...).   How can I "programmatically" detect and remove such situations? I don't mind doing it in the shapefile or later in the OSM XML.  Note 1 - The attributes (tags) are unique - the actual spatial geometry is duplicate.  Note 2 - I want to use something like ogrinfo, ogr2ogr etc GDAL libraries either as commandline tools or as import library for python/java code. If other code tools exits it's perfect also.
37804
I have recently migrated from ArcGIS to QGIS.  Is there any way to identify a feature having multiple layers? I am currently working with about 400 shape files and need to know which is the one I'm currently working on. When I click the polygon I want to identify with the identify tool nothing happens unless I have the layer selected in the layer panel. The same happens with the selection tool.  How can I fix this? In ArcGis I could identify any feature without having it selected on the layer list and I've looked through the settings of QGis and found nothing.
11649
I've created polygons from a table that has two columns- an OBJECTID and a string of coordinates (Polygon_Coordinates). The resulting polygons (called &quot;testing&quot; in the code below) are in the correct locations, but I can't seem to figure out how to carry over the ID, which I need for a join later in the workflow. Any idea on how to build geometry, but maintain the attributes? fields = ['Polygon_Coordinates', 'OBJECTID']  with arcpy.da.SearchCursor(table, fields) as table_cursor:     for row in table_cursor:         #skip null rows         if row[0] != '-9999':                          #turn string of coordinates into a list but split them at the commas             coords= list(row[0].split(','))                          #break up list into list of pairs             pairs = [coords[i:i + 2] for i in range(0, len(coords), 2)]             coord_ints = [[float(i) for i in p] for p in pairs]              #create insert cursor for geometry creation             geocursor = arcpy.da.InsertCursor(testing, [&quot;SHAPE@&quot;])             array = arcpy.Array()                          #grab pairs from list, put into array             for a in pairs:                 array.add(arcpy.Point(a[1],a[0], ID=row[1]))                          #set crs, build polygon              wgs = arcpy.SpatialReference(4326)             poly = arcpy.Polygon(array, wgs)             geocursor.insertRow([poly])
28539
In QGIS, is there a way to count the number of vertices of polygons and lines in a given layer, and create a separate field containing these values?   I suspect it's a function somewhere in the field calculator but I can't find it.
38524
I need to extract the Lat/long coordinates of the centroids of districts. My QGIS project SCR and the different layers have all been set on "WGS 84 / UTM zone 18N".   I've created the centroids using the usual tool. I could then extracted the coordinates using the "Vector > Geometry Tools > Export/Add Geometry Columns", or saving the layer in CSV typing "GEOMETRY=AS_XY" in the "Layers" part of the "OGR creation options".  Nevertheless, both methods output Cartesian coordinates, whereas I need Lat/long coordinates.
27002
I can access ESRI .GDB data using OSGeo's OGR. The following code gives feature class names embedded in .GDB...  from osgeo import ogr  driver = ogr.GetDriverByName("FileGDB") data = driver.Open(r"D:\pycharm_development\turkiye_db.gdb", 0)  feature_class_list = []  for i in data:     foo = i.GetName()     feature_class_list.append(foo)     feature_class_list.sort()  print feature_class_list   But I cannot access ESRI .GDB data in PyQGIS environment, unfortunately. PyQGIS works properly in my PC and .SHP files can be loaded successfully...  Is QgsVectorLayer() approach true or should QgsDataSourceURI() class be used to handle that?  P.S. I installed from OSGeo4W 64-bit installer. I'm using PyCharm IDE.
100823
I have just updated a table of polygons with a query which returned:  UPDATE parcel SET wkb_geometry = ST_Multi(wkb_geometry)  UPDATE 399212  Query returned successfully in 25 secs.   Now, all of the rows should contain multipolygons.  However, when I try validating geometries with ST_MakeValid, it turns out that there are geometry collections in stead of multipolygons.  How can I fix this or remove the geometry collections?   UPDATE parcel SET wkb_geometry = ST_MakeValid(wkb_geometry)  WHERE ST_IsValid(wkb_geometry) = 'f'  ERROR:  Geometry type (GeometryCollection) does not match column type (MultiPolygon) NOTICE:  Too few points in geometry component at or near point -121.78764087332523 37.700189714113364
81087
In QGIS 3.16.  I have a layer of 1000+ polygons, many of which are adjacent (touching, overlapping, or one completely inside another).  If all of the adjacent polygons are merged, I will end up with between 100 and 200 (larger) polygons. I would like to accomplish this in a way that preserves all of the attributes for all polygons, for example:  For polygons being merged: values for attribute X are concatenated for the resulting polygon.  (Example: For attribute 'status', Polygon A has value &quot;IC&quot; and Polygon B has value &quot;NC&quot;.   If these two polygons merge into Polygon AB, I would like the corresponding value of attribute 'status' to be &quot;IC, NC&quot;.)  For polygons not being merged (i.e. isolated ones without an adjacent neighbor) there is no change to their attributes.   This seems like a fairly common task that it should be possible to accomplish, but my searches have been fruitless thus far. I'd like to stay within QGIS if possible (I have never used PostGIS before).  If your answer involves SQL or Python, please consider that I am learning these now but an absolute beginner, so I will not understand code without context.
82200
I have over sampled polygons that I need to simplify, without changing the shape. basically, I want to reduce the number of vertices, by eliminating the ones that are useless and have the polygons represented with the significant vertices only. I used to do that with ET GeoWizards Plug-in, but I don't have a license anymore. My table has 500.000 features, water polygons.   Any ideas?
120582
What I'd like to try and do is intersect some point buffers with census tracts, maintain their ID's and the tracts attributes.  I found a sample from  but can't exactly substitute the cascaded union for an intersect. I'm also having trouble getting the intersection function to import from shapely.ops.   from shapely.geometry import Point, mapping, shape from fiona import collection #from shapely.ops import intersection import shapely.ops  bufSHP = 'data/h1_buf.shp' intSHP = 'data/h1_buf_int_ct.shp' ctSHP  = 'data/nyct2010.shp' with collection(bufSHP, "r") as input:     schema = input.schema.copy()     with collection(intSHP, "w", "ESRI Shapefile", schema) as output:         shapes = []         for f in input:             shapes.append(shape(f['geometry']))         merged = shapes.intersection(ctSHP)         output.write({             'properties': {                 'uid': point['properties']['uid']                 },             'geometry': mapping(merged)             })   I've also got the code and sample shapefiles up here     UPDATE:  So for some reason using Shapely, the larger buffers (1 km) I lose some of the features (census tracts) in the intersect.   Also, since the Shapely responder said the OGR command is good to use I started looking for into that. Anyway, I was able to test cd'ing to the directory and it works great. However, I've been trying to experiment with it so I can loop through the many sized buffers and dif. census years. However, why is it that I cannot get the following script to work. Can I not substitute paths for the folder 'data' in the ogr2ogr response below?   import os wp = '/Volumes/Echo/GIS/projects/naas/tasks/201411_geoprocessing/data/processing/' folder = wp+'test' theGDALcmd = 'ogr2ogr -sql "SELECT ST_Intersection(A.geometry, B.geometry) AS geometry, A.*, B.* FROM nyct2010 A, hr1000m B WHERE ST_Intersects(A.geometry, B.geometry)" -dialect SQLITE '+folder+' '+folder+' -nln hr1000m_int_ct10_ogr_pytest' os.system(theGDALcmd)   The error I get is   sh: ogr2ogr: command not found   However, when I go to the terminal, I have access to ogr2ogr.     UPDATE2:  Mike T include some code so I can run this ogr2ogr command in python.
47705
I have a database of almost 10k crimes, which are divided in to 10 categories and plotted on a map  I also have a database of 12k addresses, which are also plotted on the map.   I aim to perform a multiple regression to determine whether there are correlations between types of crime and house price.  I have created a buffer of 250 meters around each of the addresses, and would like to list a count of each of the crimes which are located within this buffered zone for each of the addresses, however, I can only get QGIS to give me a count of all types of crime, rather than the specifics.   Does anyone know how to do a point to polygon analysis of this type? I am in the middle of breaking the crime databases to analyse each one separately, which is a bit difficult!
8235
I have a shapefile that I was working on in ArcGIS Desktop 9.3 get corrupted somehow and it gives me the error "Number of shapes does not match the number of table records.". What I would want is to recover this shapefile as it has a lot of edits that other revisions of the file do not have.  Earlier I recovered from this error using  but the tool now just crashes. I have even tried the command line version ogr2ogr but still no luck. This script,  from the ArcScripts website didn't help either.  Any ideas? (except that I stop using shapefiles)    Here is the output from ogr2ogr (based on a a suggestion in the answers):
8949
I am trying to export polygon coordinates from a shapefile to a CSV file, but so far all my attempts have failed. I have found numerous questions and answers about this, but none have solved my problem.   I have downloaded the file   www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_admin_0_countries.zip  which is a shapefile containing a basic world map. I have imported the shapefile into QGIS by adding a vector layer, and then I try to export the polygons with coordinates for each country. The tips that I have found suggest either saving the layer by right-clicking it and then selecting Save as or opening the attribute table and copying it into Excel. If I try these I only get master information with one row for each country in the map.   Does anyone know how I can retrieve detail information for each country containing the polygons with coordinates?
119192
So I'm working on a project that's been in development for over a year, but I only recently got involved. My task involves converting roughly 2,500 KML files into another format, importing these files into a Geoserver, and then copying over the associated style information for each file. I realize that Geoserver allows you to import KML files directly, however, our files never seem to render correctly, and my boss would like to move away from KML format for philosophical reasons.   Using ogr2ogr, I've tried to convert these files into ESRI Shapefiles, however the conversion process only worked on roughly a third of the files and erased some of the metadata called for in the style information. The files that didn't convert code for polygons and points, which I've read can be an error for other programs like QGIS.  I've also tried to put all of the KML files into a PostGIS database and convert them like that. However, that seems to delete all of the data leaving essentially blank tables for import.  TL;DR I need to find a way to convert 2,500 KML files into a format usable by Geoserver, and will work with XML style information. I'm a complete GIS noob and this is my first time posting, so I'm sorry if this seems a bit ridiculous.
78283
I have a polygon shapefile that has a 100MB .dbf, and 500MB .shp file component. The reason it is so large, is that it is  classified as a landbase for a whole district.   Everytime I view the file in ArcCatalog, or ArcMap, and move the view window slightly, the entire file needs to redraw from scratch. I have tried spatial indexing and importing into a geodatabase - neither approach provides any noticable performance improvement with respect to rendering.  Esri's help page suggests that that to improve shapefile performance, the user can . While this would obviously work, I do not want to lose any information. Splitting the file up is not ideal since I am doing a lot of geoprocessing/queries with its entire area. I guess I could avoid viewing the entire area at once - but sometimes, for example, it is good to see what parts of the file a query has selected.  Is there any other approach I could take to improve rendering performance?   (In theory, building shapefile "pyramids" would be ideal - I'm unsure why ArcGIS has never supported such an approach  - at least that I am aware of...)
55500
Using ogr2ogr and python, I'm running into a wall with trying to create a CSV with WKTs for a shapefile that contains multipart polygons. Currently this is this code I'm using (found it on internet):   #Purpose: To export a shapefile to WKT  from osgeo import ogr import sys, os  input = ogr.Open(sys.argv[1])   layer_in = input.GetLayer() layer_in.ResetReading() feature_in = layer_in.GetNextFeature()  outfile = open(sys.argv[1] + ".wkt", "w")  while feature_in is not None:      geom = feature_in.GetGeometryRef()     geom_name = geom.GetGeometryName()      outfile.write(str(geom)+ '\n')      feature_in = layer_in.GetNextFeature()   So, do I need to use a different geometry container or do I need to evaluation each feature and if it's a multipart use a different set of geometry classes? I've looked around in the gdal/ogr documentation but I'm having a hard time reconciling it.
6599
I have to import large Shapefiles (> 1 million records) into PostGIS, and I have been wondering about the best way to do it.    In my question I used the word "hack", instead of tool, on purpose because I think this is not so much a matter of which tool, but which set of steps, or configuration settings to use. So far, I have tried the  plugin (QGIS), the  Postgis tool and the GDAL  tool. You can view my full review on  post. So far, I find all of them really unresponsive, when dealing with a large dataset. I was wondering if someone experienced a similar issue, and if you could share something about the approach.