0

I have a large shapefile (saleArea.shp) which includes hundreds of small adjacent polygons. I would like to dissolve the polygons based on some conditions from tValues field into 5 bigger groups like

1-  "tValues" <= 0.151560
2-  "tValues" >= 0.151561 AND "tValues" <= 0.254022
3-  "tValues" >= 0.254023 AND "tValues" <= 0.379095
4-  "tValues" >= 0.379096 AND "tValues" <= 0.540042
5-  "tValues" >= 0.540043 AND "tValues" <= 0.846651

I did this manually by using Select By Attribute for each of the groups then export them as a new shapefile. After that, I used the Dissolve tool on each of the layers and eventually merged all the dissolved layers - which was tedious work (Besides I have more than 50 shapefiles and I must repeat this for all!). Can you please let me now how to do this is by Arcpy?

Update

I tried to do this as PolyGeo commented by using the Python parser

if ("tValues" <= 0.151560):
        return 1
elif ("tValues" >= 0.151561 AND "tValues" <= 0.254022):
        return 2
elif ("tValues" >= 0.254023 AND "tValues" <= 0.379095):
        return 3
elif ("tValues" >= 0.379096 AND "tValues" <= 0.540042):
        return 4
elif ("tValues" >= 0.540043 AND "tValues" <= 0.846651):
        return 5    

but I am getting this error

enter image description here

1
  • 1
    Make sure you are using consistent spacing. Take a look at the examples for code blocks and functions.
    – Paul
    Aug 18, 2015 at 17:53

2 Answers 2

2

There is no need to use ArcPy for this.

You can use the Field Calculator with its Python parser and if/elif(x4) to return values of 1 to 5 to a field, perhaps called GROUP.

You can then Dissolve on GROUP to get the five features that you desire.

5
  • Hi PolyGeo, this sounds interesting but the first part looks a little bit confusing! Can you please let me know how to do this?
    – Suffii
    Aug 18, 2015 at 9:43
  • 1
    @Behseini Polygeo means that you should add a new field and compute the class values with the field calculator. See gis.stackexchange.com/questions/113407/if-then-field-calculator/… for an example of if statement. You can add all your condition if/elif/elif/elif/else
    – radouxju
    Aug 18, 2015 at 9:58
  • Thanks radouxju, well, it seems juicy but not sure hoe to write the expression for example to return 2 for all "tValues" >= 0.151561 AND "tValues" <= 0.254022
    – Suffii
    Aug 18, 2015 at 10:04
  • Thanks PolyGeo, Can you please take a look at the update code and let me know what I am doing wrong on the code?
    – Suffii
    Aug 18, 2015 at 17:52
  • @Behseini In that code you are asking whether the string "tValues" is >= 0.151561 - you need to test whether the current value of a number variable called tValues is >= 0.151561 i.e. use tValues >= 0.151561. Also, questions like this are usually easy to debug if you also include a screenshot of the tool dialog so that we can see you have set the Parser, Expression and Code Block all correctly.
    – PolyGeo
    Aug 18, 2015 at 22:02
1

If anything becomes tedious and repetitive then it's time to get smarter with your processing. You can automate all that you described by using modelbuilder. You drag the tools you used in to modelbuilder, connect them together to create a work flow and then run the model. You'll invest a bit of time creating the model but then you can tweak a parameter and run the whole model again. There are even ways of making the model loop (called iterators). Basically it's time for you to read the Help manual! Go to Desktop > Geoprocessing > Modelbuilder.

1
  • Actually I already did but not sure why it is not working properly! I mean I am getting 5 Classify at the end but not sure why the last classify over lap on top of all
    – Suffii
    Aug 18, 2015 at 9:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.