Select to view content in your preferred language

Separating One Layer into different layers based on Longitude

1362
7
Jump to solution
10-14-2014 07:27 AM
RicM
by
Deactivated User

Hello Experts,

I am given a shape file which consists of polylines  in just one

layer and my task is to separate them into three layers based on

the longitude of the vertices of the said polylines.  So that

polylines whose vertices are between say 100 to 110 should be in

LayerA, and those between 111 to 120 should be in LayerB .. is this

possible to do in python?

Any help greatly appreciated

Gratefully,

Ric

P.S.

I am a bit new at this .. so far as starters, I have succeeded in extracting the latitudes and longitudes
using the technique  below but I am not sure if my approach is  the the right way or if there is a more
correct/proper way to do it.

import arcpy

strKPipeLayer = 'TestPipeLines'

strKPipeFullPathShape = r"F:\TestPipeLines.shp"

strK = r"F:\creatingMeridians.mxd"

mxd = arcpy.mapping.MapDocument(strK)

for ly in arcpy.mapping.ListLayers(mxd):

   if (ly.name == strKPipeLayer):

      rowData = arcpy.SearchCursor(strKPipeFullPathShape)

      for rowDatum in rowData:

         arcpy.Describe

         poly = rowDatum.Shape

         lst = list(poly)

         ary = arcpy.Array(lst)

       

         for ply in  ary:

            countPoly = countPoly + 1

          

            print "Polyline # " + str(countPoly)

            print ' '

            counter = 0

            for pt in ary[0]:

               xcoord = ary[0][counter].X

               ycoord = ary[0][counter].Y

             

               point = arcpy.Point(xcoord,ycoord)

               ptGeometry = arcpy.PointGeometry(point)

             

               print str(xcoord)  +  ','  + str(ycoord) + ',' + '0.0000'

             

               counter = counter + 1

Message was edited by: Curtis Price (added code highlight in-place)

0 Kudos
1 Solution

Accepted Solutions
curtvprice
MVP Esteemed Contributor

1. Arcpy.mapping is for interacting with the map display, you can access the shapefile directly by path if you want.

2. What if a line crosses those boundaries?

3. Don't forget to delete your cursor when you are done with it:

del RowDatum, RowData

A more brute force approach that does not require editing geometry may be to use the Create Fishnet tool and then use overlay tools to select or clip your geometries. You could do this in ModelBuilder with no coding.

View solution in original post

0 Kudos
7 Replies
BlakeTerhune
MVP Regular Contributor

If you use the syntax highlighting feature (under the advanced editor) of the forums here, it helps present your code in a more readable way.

(see above - cp)

0 Kudos
RicM
by
Deactivated User

Hello and thanks for the highlighting technique info ... the code looks much more readable indeed ..

0 Kudos
curtvprice
MVP Esteemed Contributor

1. Arcpy.mapping is for interacting with the map display, you can access the shapefile directly by path if you want.

2. What if a line crosses those boundaries?

3. Don't forget to delete your cursor when you are done with it:

del RowDatum, RowData

A more brute force approach that does not require editing geometry may be to use the Create Fishnet tool and then use overlay tools to select or clip your geometries. You could do this in ModelBuilder with no coding.

0 Kudos
RicM
by
Deactivated User

Thanks for all the valuable info you have given ..

If a line crosses the boundaries the work flow would be that a  copy of the polyline needs to be
created  so that both LayerA and LayerB would have the polyline … one layer would have
original and the other layer would have its copy.

Thanks for the Fishnet tip, I really appreciate it .. I am going to do further research how to use
this technique ... for additional fire power ..

Unfortunately, for  the tool I am building  there is a need to be coding based, the reason
being that they are intending to divide the two layers into many many  layers   which could present
a problem if  not in code.

So far, the biggest problem I have is I do not know what can and can’t be done using python and
arcpy ... I do not know it's limits … so that if I pursue a direction I am not sure if I’d end up shipwrecked.

  Wondering if a plan to populate the attribute table with info saying that the corresponding
polyline in the row is  between 100 to 110" another column  which says  "polyline is between 111 to 120" and
a third one which says  "polyline is in both 100 to 110 and 111 to 120"  etc.  and then trying
to change the layer of the entities (and create needed copies of the polylines) based on those three
columns’  Yes/No value  is possible?

If the plan won't work because it is beyond the capability of arcpy and python the guidance telling me that
what I am thinking of is impossible  would greatly  help me focus my energy on finding a different strategy.

Any other strategy, advise, enlightenment, link, or any idea much appreciated .. thanks again

Gratefully,

Ric



0 Kudos
RicM
by
Deactivated User

I do not know how to close a topic ... please consider this topic closed ...  the technique I used is to continue on with the creation of the columns corresponding to the shape file just like I mentioned in my plan above and populate it programmatically and then let the code continue from there ...  thanks

0 Kudos
curtvprice
MVP Esteemed Contributor

Happy my post helped.

> If the plan won't work because it is beyond the capability of arcpy and python

Python/ArcPy includes the ability to do things with python modules outside of the ArcGIS universe - so there really aren't a lot of limits to what you can do -- or , different ways to accomplish a task!

> I do not know how to close a topic ... please consider this topic closed

By marking an answer correct you have "closed" the thread as much as you can. But the thread remains open  if anyone has anything they want to say in the future!

RicM
by
Deactivated User

>>so there really aren't a lot of limits to what you can do
Thanks for these encouraging words ... I will always keep them in mind in all my developments ... thanks again

0 Kudos