Esri posted a great blog post on building an add-in using python. You can find the information here.
Enjoy
Tuesday, August 28, 2012
Friday, July 20, 2012
The Tile Package
What is it?
New at 10.1, tile packages are compressed files that contain a map document's cached data. The tile package or .tpk is ideal for disconnected use and for sharing information to ArcGIS Online.
Why Should I Care?
It makes sharing cache easy, and you can create custom caches on the fly. From a geoprocessing/application view of things, this means you can get your data out to mobile users without needing an air card. It also produces an easy way to share cache from server to server or AGOL.
Other reasons include:
You can create a package using geoprocessing as follows:
Have packaging
New at 10.1, tile packages are compressed files that contain a map document's cached data. The tile package or .tpk is ideal for disconnected use and for sharing information to ArcGIS Online.
Why Should I Care?
It makes sharing cache easy, and you can create custom caches on the fly. From a geoprocessing/application view of things, this means you can get your data out to mobile users without needing an air card. It also produces an easy way to share cache from server to server or AGOL.
Other reasons include:
- Improved rendering performance
- Improved quality
- Follows industry standards (AGOL, Google, Bing, etc..)
You can create a package using geoprocessing as follows:
import os
import arcpy
from arcpy import env
# Set environment settings
env.overwriteOutput = True
env.workspace = "C:/Tilepackages/"
# Loop through the workspace, find all the mxds and create a tile package using the same name as the mxd
for mxd in arcpy.ListFiles("*.mxd"):
print "Packaging " + mxd
arcpy.CreateMapTilePackage_management(mxd, "ONLINE",
os.path.splitext(mxd)[0] + '.tpk', "PNG8", "10")
Pretty easy to create. It should be noted that your ArcMap Document's extent determines the area to be processed. You can embed web service layers as well as local data. The cached is fused together and it means you cannot query the base data as well.Have packaging
Labels:
ArcGIS 10.1,
ArcPy,
GP Task,
Programming,
Scripting
Tuesday, July 17, 2012
Create a Map Service Layer (10.1)
At 10.1, you can use JSON to create maps and add map services to that layer. This means you can create map service layer indirectly. There is no direct way to create a map service layer in 10.1, but by using the ConvertWebMapToMapDocument() you can. Information about the function can be found here.
ConvertWebMapToMapDocument() described in the help is as follows:
You notice that the help does not directly mention the creation of the map service layer, but when you drill down into the supported JSON syntax, you can see how you can use this method to generate your map service layer.
A JSON map consists of the following:
Using the JSON library and dictionaries, you can easily match this structure. As shown below:
Now we have a MapDocument object that has our map service layer in it. Using the other rmapping module functions, loop through the TOC and save the layer to disk.
mxd = result.mapDocument
layers = mapping.ListLayers(mxd)
for layer in layers:
layer.saveACopy(saveLayer)
break
That's it, now we have create a map service layer saved to disk. If you have to deal with security, you can add a token to your operational layer.
Enjoy
ConvertWebMapToMapDocument() described in the help is as follows:
Converts a web map (in JSON format) that you intend to print or export to a map document. The map document can be further modified before finally being printed or exported.
You notice that the help does not directly mention the creation of the map service layer, but when you drill down into the supported JSON syntax, you can see how you can use this method to generate your map service layer.
A JSON map consists of the following:
{ "mapOptions": {}, "operationalLayers": [], "baseMap": [], "exportOptions": {}, "layoutOptions": {} }
Using the JSON library and dictionaries, you can easily match this structure. As shown below:
import jsonfrom arcpy import mapping
mapService = {} operationalLayer = [] layer = {} layer["id"] = str(webmapID) layer["url"] = str(url) layer["title"] = str(title) layer["opacity"] = str(opacity) layer["visibility"] = str(visibility) layer["minScale"] = str(minScale) layer["maxScale"]= str(maxScale) operationalLayer.append(layer) mapService["operationalLayers"] = operationalLayer jsonDump = json.dumps(mapService) result = mapping.ConvertWebMapToMapDocument(jsonDump)
Now we have a MapDocument object that has our map service layer in it. Using the other rmapping module functions, loop through the TOC and save the layer to disk.
mxd = result.mapDocument
layers = mapping.ListLayers(mxd)
for layer in layers:
layer.saveACopy(saveLayer)
break
That's it, now we have create a map service layer saved to disk. If you have to deal with security, you can add a token to your operational layer.
Enjoy
Labels:
ArcGIS 10.1,
ArcPy,
Programming,
Python
Monday, July 16, 2012
Constructing Polygons at 10.1
Polygon geometries are closes paths forms from a series of X,Y coordinates. A polygon geometry object can be constructed from using an Array object containing the arcpy.Point(X,Y) values.
In this example, I will construct the extent of a feature class as a polygon to clip another datasource:
Notice how we didn't have the close the polygon! The object does it for us.
Enjoy
In this example, I will construct the extent of a feature class as a polygon to clip another datasource:
import arcpy
dsParcel = r"c:\temp\sample.gdb\Parcels"
dsLandUse = r"c:\temp\sample.gdb\LULC"
pnt = arcpy.Point()
array = arcpy.Array()
extentParcel = arcpy.Describe(dsParcel).extent
coords = [[extentParcel.XMin,extentParcel.YMin],[extentParcel.XMax,extentParcel.YMin],
[extentParcel.XMax,extentParcel.YMax],[extentParcel.XMin,extentParcel.YMax]]
outLU = r"c:\temp\sample.gdb\clipLULC"
# Create Spatial Reference
sr = arcpy.SpatialReference()
sr.factoryCode = 4326
sr.create()
# Load the Location
for coord in coords:
pnt.X = coord[0]
pnt.Y = coord[1]
array.add(pnt)
polygon = arcpy.Polygon(array,sr)
arcpy.Clip_analysis(dsLandUse,polygon,outLU)
Notice how we didn't have the close the polygon! The object does it for us.
Enjoy
Labels:
ArcGIS 10.1,
ArcPy,
Python
Friday, July 13, 2012
Create a List of Geometries (10.1)
At 10.1, you can use geometries directly in geoprocessing functions like Clip or reading geometry properties. Here is a tip to copy all the geometries into memory and use it as a list:
Example:
The CopyFeatures() copies the results as a geometry object to a list and the area property is a standard Geometry object property.
Enjoy
Example:
import arcpy
ds = r"c:\temp\sample.gdb\Parcels"
g = arcpy.Geometry()
geomList = arcpy.CopyFeatures_management(ds,g)
# Get the Area (Sq Ft)
area = 0.0
for geom in geomList:
area += geom.area
print "Total Parcel Area: {0}".format(area)
The CopyFeatures() copies the results as a geometry object to a list and the area property is a standard Geometry object property.
Enjoy
Labels:
ArcGIS 10.1,
ArcPy,
Programming,
Python
Thursday, July 12, 2012
ArcGIS Python Window Color Scheme
If you are like me, I prefer dark backgrounds and white or bright text verse the standard white on black.
The python window color scheme can be changed by doing the following:
The python window color scheme can be changed by doing the following:
- Right click on the python window
- Select Format
- Select 'Set Black Theme'
Labels:
ArcGIS 10,
ArcGIS 10.1,
Environment
Wednesday, July 11, 2012
Subscribe to:
Posts (Atom)