Hot answers tagged

15

You can use the GDAL/OGR python API, the code will be like that: from osgeo import ogr shapefile = ogr.Open( "shapfile.shp",1 ) layer=shapefile.GetLayerByIndex(0) count=layer.GetFeatureCount() for feature in range(count): layer.DeleteFeature(feature)


12

The command line ogr2ogr with a where clause guaranteed to create empty results is one quick and easy method: ogr2ogr output.shp input.shp -where "FID < 0" The overview page for python and OGR (and GDAL) is http://trac.osgeo.org/gdal/wiki/GdalOgrInPython


11

Sample code to do 1. is on the Online Help for AddLayer (arcpy.mapping). The steps for 2. are in the Online Help for Publishing a map service with Python. Note that it is not possible to create an MXD using ArcPy - you need to have an existing MXD to which you can add layers. That design decision is described in the Online Help on Guidelines for ...


10

You can do this in pyshp. It's simple but not obvious because I never envisioned this use case. But it does make sense for automated update applications. I tested the following 6 lines of code and it worked great: import shapefile r = shapefile.Reader("myshape") w = shapefile.Writer(r.shapeType) # This line will give us the same dbf schema w.fields = ...


10

Put your script in .qgis/python/startup.py and it should run when QGIS is opened. However, this will run with any project you open, which you may not want. So you might be better off setting up a python macro in the specific project. File > Project properties > Macros. Enable macrcos by checking the box. def openProject(): wack your code here! def ...


9

I had the same problem last year : a few dozen of maps to produce within three days, same legend, but different locations. I used this setup : vector data in PostGIS raster data in GeoTiff (shaded relief) cartographic engine : MapServer, with PDF vector output batch processing : PHP to automate MapServer, with MapScript PHP finalization with Adobe ...


9

Automatic generalization algorithms are not yet a complete solution, they still often make decisions a careful cartographer would abhor. Natural Earth has a good background article on how their approaches to generalizing features, a multi-step manual process. Axpand claims the Swiss Topography Office had an 80% success rate with automatic generalization ...


8

I use the ftools plugin in Quantum most of the time. I also use the v.generalize in GRASS. It has the advantage of giving you several different algortithms options for simplification, smoothing, and network generalization depending on what you are trying to do. http://grass.itc.it/gdp/html_grass64/v.generalize.html


8

With help from Mark Cederholm I have a working solution using python and arcobjects. It's rough around the edges, but it got the job done. After following the recipe on that page, create a new script which uses the GetLibPath, NewObj, CType, OpenFeatureClass functions from snippets.py. Also create the rename lookup tables in .csv format: Field to Field ...


8

In GRASS GIS, you can use v.edit's snap tool. snap: Snap vector features in given threshold There are options to snap to a node or a vertex.


8

This isn't really a standalone answer, more of an addition to @PolyGeo's answer as it addresses the 'mxd creation from scratch' in python issue. Note: it's probably a bit advanced for a python 'new bee'... You can create MXD's from scratch in python if you access ArcObjects. You will need the comtypes package and if using ArcGIS 10.1, you need to make a ...


8

For pure Python, use GDAL's OGR module: import os from osgeo import ogr from glob import glob # Establish a connection to a PostGIS database pg = ogr.GetDriverByName('PostgreSQL') if pg is None: raise RuntimeError('PostgreSQL driver not available') conn = pg.Open("PG:dbname='postgis' user='postgres'", True) if conn is None: raise ...


8

The most efficient way to make bulk changes to multiple documents is to use Python scripting available in ArcGIS. You would need to write a Python script that will iterate (or go through) each of the map document files you have and apply the changes you specify in the code. Start looking for the arcpy.mapping module. 10.1 and 10.2 have more functions ...


7

Why not save a copy of the blank Shapefile and over-write your Shapefile of interest.


7

Adding this line fixes the issue ESRI.ArcGIS.RuntimeManager.BindLicense(ESRI.ArcGIS.ProductCode.Desktop);


7

If using the Web Archive: download the war file and deploy it, then login and make all customizations (remove layers, adjust defaults, etc) until it suits you. Now shutdown the servlet container, zip the geoserver directory and rename the resulting geoserver.zip as .war and you're done. A .war file in fact is just a .zip file in disguise. IMPORTANT: ...


7

Never, never, never use embedded cursor loops. Never! It is bad for performance, memory, data safety, etc. It is very, very bad. See my blog on Turbo Charging Data Manipulation with Python Cursors and Dictionaries. Load the look up table into a dictionary with a data access search cursor, then update the other table with an update cursor by matching it ...


6

Here's how to do it Model Builder in ArcGIS 10. This will take the selected features of VectorTiles and clip the InputRaster by each selected feature saving it to the Default.gdb with the TileID as part of the new raster name. Iterate Feature Selection is added from the Insert menu. TileVectors is the Input Features and the group field is a unique tile id ...


6

If you have access to ArcMap, examine the arcpy mapping module: Arcpy.mapping is a Python scripting module that is part of the ArcPy site package. It gets installed with ArcGIS for Desktop and is available to all licenses. It was designed primarily to manipulate the contents of existing map documents (.mxd) and layer files (.lyr). and also Data ...


6

For a fantastic way to detect, visualize, and report your findings to the public, check out the Landtrendr (Landsat-based Detection of Trends in Disturbance and Recovery) program from OSU. The Landtrendr program is one of the most exciting recent developments in change detection research. There is very good documentation on the methods, and Landtrendr code ...


6

You can do it in three steps: Get group names, create groups, and move layers. For testing purposes, I've replicated your sample scenario: Run the following code snippet in your QGIS Python console: # 1. Get group names and list of layer ids root = QgsProject.instance().layerTreeRoot() dictGroups={} for layer in root.findLayers(): if ...


5

This code works for me in 9.3.1 ... public static void TestAlterAlias(IApplication app) { // make a dictionary of old/new names Dictionary<string, string> nameDict = new Dictionary<string, string>(StringComparer.CurrentCultureIgnoreCase); nameDict.Add("qsectionalias", "qsectionalias2"); nameDict.Add("sursysalias", ...


5

Is is possible that LIDAR has been flown recently in the area? You can extract buildings this way... LIDAR would most likely be too expensive to fly yourself, probably at least 8-12k for an area that size. http://knol.google.com/k/aerial-extraction-of-roof-surfaces-for-solar-analysis# Found that article, may be of some help.


5

I did something similar a few months back. As you can see, you run into a classification limitation with las tools ... I'd be interested to see your output from the feature analyst for comparison. As far as making it better, you can't. That is unless you can classify the points more correctly ... Here is a link to an interesting article on overhanging ...


5

I've developed a model/method before for identifying areas/features that labels are overlapping. The work flow goes something like this: Determine distance between features that labels usually overlap (e.g. 50ft, 500ft, 1000ft...etc). Buffer labeled feature by distance from step 1. Run Intersect tool on buffer result. Join result of Intersect tool layer ...


5

There exists an extremely efficient solution to this problem that avoids computing ten thousand grids of interpolated data. Using IDW to estimate precipitation tends to give poor results, so I will provide a more general answer that applies to better procedures such as Kriging as well as IDW. What is common to these interpolation procedures is that they ...


5

There is a distributive flow tool available in the applications prototype lab. Here is a blog and some links and data. Even if you are not looking for this. I like it so here. Credit: Brad Simantel With your edit addition to the question I will add this link for placing line decorations with code. If you desire more help on using arrows add to your ...


5

I'm not familiar with programming in JavaScript but in the OpenStreetMap Wiki there is a section describing "Mercator". Following this link you'll find a sample code snippet to tranform from lat long to mercator. I actually don't know if it's correct because I did not test the code.


5

The easiest way to see these updates as changes are made to the csv is to use the "Add Delimited Text Layer" button and choose "watch file" as one of the options. I noticed with the spatial index feature enabled, it doesn't update the layer extent (so the zoom to layer button doesn't do what it's supposed to) or the index as new features are added, so maybe ...


5

Saving this in a Python file and using it in the --code arg should do what you need: from PyQt4.QtCore import * from PyQt4.QtGui import * import os from qgis.core import * from qgis.gui import * from qgis.utils import iface for comp in iface.activeComposers(): print comp folder = r"C:\temp" title = "testing" printer = QPrinter() ...



Only top voted, non community-wiki answers of a minimum length are eligible