|
POST
|
In ArcMap, if you have a polygon layer named, "Parcels" which has coordinate system using meters as the unit, the following code will produce the inside 100m buffer and place in an in-memory layer called, "ringBuffs" (paste into the Python window). You could change that path to disk if you choose (e.g. r'C:\spatialData\ringBuffs.shp'): >>> fc = "Parcels"
... distance = -100
... buffs = []
... with arcpy.da.SearchCursor(fc,"SHAPE@") as cursor:
... for row in cursor:
... ringBuff = row[0].difference(row[0].buffer(distance))
... buffs.append(ringBuff)
... arcpy.CopyFeatures_management(buffs,r'in_memory\ringBuffs') Chris' suggestion for buffer/clip works just as well, but you need to run two things, rather than this one thing.
... View more
04-14-2015
08:54 AM
|
0
|
0
|
4736
|
|
POST
|
If I understand correctly, you want to create an inside ring buffer, without going through the trouble of making your negative buffer and erasing it from the original polygons. You can bypass that step using Python. The following makes inside buffers 10m (due to the input coordinate system) in from polygon boundaries in the feature class "Parcel Selection": >>> fc = "Parcel selection"
... buffs = []
... with arcpy.da.SearchCursor(fc,"SHAPE@") as cursor:
... for row in cursor:
... ringBuff = row[0].difference(row[0].buffer(-10))
... buffs.append(ringBuff)
... arcpy.CopyFeatures_management(buffs,r'in_memory\ringBuffs')
... View more
04-13-2015
02:57 PM
|
1
|
4
|
4736
|
|
POST
|
Ah, yes, there are some subtle differences running Python inside or outside of ArcMap. Glad it's making sense.
... View more
04-13-2015
11:47 AM
|
0
|
0
|
601
|
|
POST
|
No, saving to in_memory is not the issue - it also adds a layer saving to disk: >>> arcpy.env.scratchWorkspace = r'C:/junk'
... mxd = arcpy.mapping.MapDocument('CURRENT')
... df = arcpy.mapping.ListDataFrames(mxd,"*")[0]
... SoilUnclass = arcpy.PolygonToRaster_conversion('asdasd', "Id", 'OutLocation', "MAXIMUM_COMBINED_AREA")
... print type(SoilUnclass)
... print arcpy.mapping.ListLayers(mxd)
... print type(arcpy.mapping.ListLayers(mxd)[1])
... arcpy.mapping.RemoveLayer(df, arcpy.mapping.ListLayers(mxd)[1])
... print arcpy.mapping.ListLayers(mxd)
...
<class 'arcpy.arcobjects.arcobjects.Result'>
[<map layer u'asdasd'>, <map layer u'OutLocation'>]
<class 'arcpy._mapping.Layer'>
[<map layer u'asdasd'>]
... View more
04-13-2015
11:45 AM
|
0
|
0
|
4145
|
|
POST
|
This may or may not help. I started with one polygon layer ('asdasd') and ran PolygonToRaster, saving to the in_memory workspace ('OutLocation'). The 'type' of the SoilUnclass object is a 'Result' not a 'Layer'. ListLayers() does return layer objects, including the newly created and added 'OutLocation' layer. You can remove the new layer by calling RemoveLayer referencing the layer object, not the result object. This leaves me with only my original layer, 'asdasd'. 'OutLocation' would still be saved on disk, though. >>> mxd = arcpy.mapping.MapDocument('CURRENT')
... df = arcpy.mapping.ListDataFrames(mxd,"*")[0]
... SoilUnclass = arcpy.PolygonToRaster_conversion('asdasd', "Id", r"in_memory\OutLocation", "MAXIMUM_COMBINED_AREA")
... print type(SoilUnclass)
... print arcpy.mapping.ListLayers(mxd)
... print type(arcpy.mapping.ListLayers(mxd)[1])
... arcpy.mapping.RemoveLayer(df, arcpy.mapping.ListLayers(mxd)[1])
... print arcpy.mapping.ListLayers(mxd)
...
<class 'arcpy.arcobjects.arcobjects.Result'>
[<map layer u'asdasd'>, <map layer u'OutLocation'>]
<class 'arcpy._mapping.Layer'>
[<map layer u'asdasd'>]
... View more
04-13-2015
10:44 AM
|
2
|
4
|
4145
|
|
POST
|
ListLayers() does not return raster datasets, it returns layers saved in your mxd that point to raster datasets. If you hit save in ArcMap (or, potentially, "mxd.save()", although I don't believe you've actually added SoilUnclass to the mxd saved on disk) once SoilUnclass has been added, you could then reference the layer that has been saved in the table of contents.
... View more
04-13-2015
10:18 AM
|
2
|
7
|
4145
|
|
POST
|
I believe this is because SoilUnclass is a raster object (data), not a layer object in your mxd. Since you never added this data to your map, there is no need (or way) to remove it. To delete data on disk, use Delete.
... View more
04-13-2015
09:54 AM
|
0
|
9
|
4145
|
|
POST
|
Case matters in Python. It is: spatialRef = arcpy.Describe(template).spatialReference Not: spatialRef = arcpy.Describe(template).SpatialReference
... View more
04-10-2015
10:54 AM
|
1
|
2
|
2466
|
|
POST
|
Not sure if this will solve your problem or not, but old-style cursors often behave unexpectedly (or predictably badly) when nested. Try converting the inside cursor to a da.SearchCursor.
... View more
04-10-2015
10:43 AM
|
1
|
2
|
3136
|
|
POST
|
You can definitely add a field to a FGDB with basic license. I do it all the time.
... View more
04-09-2015
11:08 PM
|
0
|
0
|
1859
|
|
POST
|
I don't think this is a licensing level issue. You can certainly add a field with basic licensing. edit: is this an SDE GDB? if so, you will have issues with basic licensing.
... View more
04-09-2015
03:01 PM
|
0
|
1
|
3092
|
|
POST
|
You could make a list of things to check (checklist below), then find the matches between it and the name: >>> name = 'john doe1'
>>> checklist = [' ','-','1','2','3','4']
>>> matches = [i for i in checklist if i in name]
>>> matches
[' ', '1']
... View more
04-09-2015
01:48 PM
|
1
|
0
|
2501
|
|
POST
|
What is the type of data you are trying to create or modify when this error occurs?
... View more
04-09-2015
01:30 PM
|
0
|
3
|
3092
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 08-30-2013 02:22 PM | |
| 1 | 04-12-2011 11:19 AM | |
| 1 | 09-17-2021 09:43 AM | |
| 1 | 04-04-2012 12:05 PM | |
| 2 | 07-16-2020 11:31 AM |
| Online Status |
Offline
|
| Date Last Visited |
07-15-2023
12:11 AM
|