Hot answers tagged automation
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)
9
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 = ...
8
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 ...
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: ...
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
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 ...
5
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.
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
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 ...
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
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
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 ...
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
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 ...
3
I had a similar requirement and put together a QGIS plugin to generate the maps, based on a shapefile with point localities for all species (it assumes a unique taxon name in the attribute table as the common identifier). My requirements were not as complex - I did not need seasonal information, titles or legend, but it may be a useful starting point for ...
2
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.
2
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 ...
2
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.
2
Another solution courtesy of Rob Clark:
You could use featureclass_to_featureclass with field mapping. Yes it
creates another feature class but you could just have an output area
to copy data and change aliases whilst it's doing it.
In python the syntax for the field_map part is tricky so go through it once interactively to set the parameters ...
2
You could set up a model that runs through the various selections, and then exports to CAD. All that would be required then is to run the model when a request comes in, or you could export it to a Python script and automate it to run on a set schedule. It will require some setup to get the model working, but it's time well spent. Here is a link to ESRI's ...
2
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 ...
2
Rather than write something to add 400 raster layers into your map (and Table of Contents) you might be better to Create a Raster Catalog from them so that just one layer results.
2
In map 3d 2010 you can set the import to use data field for layer name. however if you have a size and type in two differing fields you would still not be able to accomplish exactly what you are talking about without another step of creating a composite field with size and type in it.
If on the other hand your data does not have concidental values (i.e. 8" ...
2
For something like this, your best bet is to start learning Python and let ModelBuilder generate the heart of your Python code for you. Then just add the components that you need to accomplish your task.
1) Start by creating a model in ArcGIS like this:
2) Export it to a Python Script with Model-->Export-->to Script-->Python which will give you the ...
2
Your question is kind of similar to one I asked before about land cover extraction. The solution that I was given was to use the open source GIS software called GRASS (see my question/answer below).
Feature Extraction - Land cover
2
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 ...
Only top voted, non community-wiki answers of a minimum length are eligible

