Tag Info

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)


10

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


9

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 = ...


9

Sample code to do 1. is here. The steps for 2. are here. 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 here but being able to create a new Map Document from nothing in ArcPy is an ArcGIS Idea I would like to see implemented. See @Luke answer for ...


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

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

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 ...


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

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 ...


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

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


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

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 ...


5

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 ...


5

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 ...


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 ...


4

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", ...


4

If you have ArcInfo workstation, there is a module called Librarian, which has an interesting command called VISIT. I'm not suggesting that you actually use Librarian, but consider looking at what VISIT does. It's been many years, and I can't find any online documentation for it, but as I recall VISIT allows you to loop through a selected set of tiles ...


4

If you are familiar with Python, you could use Qgis Python console with something like that: #get a pointer to active layer layer=iface.activeLayer () #get a copy of selected features features=layer.selectedFeatures () #create a new feature and a new geometry to hold the output newgeometry = QgsGeometry() newfeature=QgsFeature() # loop for feature in ...


4

you can do this with Add Field (Data Management). Syntax AddIndex_management (in_table, fields, {index_name}, {unique}, {ascending}) import arcpy from arcpy import env env.workspace = "C:/test.gdb" inFeat = "cityoflondon.shp" fieldLength = 10 #it will return "cit" from inFeat fieldName = str(inFeat[:3]) arcpy.AddField_management(inFeat, ...


4

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 ...


4

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 ...


4

Not sure if it helps you, but this was my workflow to tile 2GB of 300 Dutch Topo maps to OSM compatible zoomlevel 15 and 16: Create vrts for each tif and expand indexed colours to RGBA: for %%N in (D:\Karten\gdal\gdal2tiles\NL25*.tif) DO gdal_translate -of vrt -expand rgba %%N D:\Karten\gdal\gdal2tiles\NL25\%%~nN.vrt Create an index vrt for all ...


4

Evil Genius seems to have a good idea, but actually the color-relief file can be set using percentages as well as min and max. So you could write the file using something like: 0% green 100% red So the command would be something like: gdaldem color-relief inputfile.img colorfile.txt output.jpg -of "JPEG2000"


3

just to follow up on SRG's FME recommendation, the Natural Resources Canada has done a significant amount of work using FME for generalization. They presented at the 2009 FME User Conference, and you can find there talk here http://www.fmeuc.com/archive/fmeuc2009/index.php (it is Talk 2. Generalizing a 1:250 000 National Topographic Map at Natural Resources ...


3

Postgis has two simplification function based both on Douglas-Peucker ST_Simplify - Returns a "simplified" version of the given geometry using the Douglas-Peuker algorithm. ST_SimplifyPreserveTopology do the same but preserve topology For theory, a reference for me is http://www.spatialanalysisonline.com Look on the web version and search "smoothing". You ...


3

You can do it in AutoCAD Map with Query and Alter Properties. export you data to shp file import it into AutoCAD Map with attribute data in Object Table save your file as dwg and close it open empty dwg file and open Task plane (MAPWSPACE) - Map Explorer attach the drawing in which you imported your shp file define a query with Location:ALL ; Query mode: ...


3

if your dataset is relatively small or tightly focussed and the end product is a map you might try exporting to a drawing program like Illustrator or Inkscape which have much more developed simplification and generalization tools. If you have deep pockets Avenza Map Publisher provides a two way bridge between ArcMap and Illustrator.


3

Rupert Brooks of the National Research Council of Canada has some open source gis tools for generalization built for the National Atlas of Canada. They're a bit older, late 1990s and early 2000s, and largely based on ArcInfo workstation though there are a couple of perl and C utilities. I thought I remembered seeing some newer arcgis toolboxes bases on ...


3

The JTS Topology suite has an implementation of the Douglas-Peucker algorithm (though it's not too hard to roll your own for that one); the Net Topology Suite (.net port of JTS) would have the same if you favor the .Net environment. Finally the NTS functions could probably be accessed through SharpMap.



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