Select to view content in your preferred language

Creating an Array based on Definition/Points

1368
6
10-03-2018 07:10 PM
JacobHorwitz1
Occasional Contributor

I'm currently new to python and working on a Class Project trying to create multiple polylines based on the tracking of Rhinos. I have the approach right, but I somehow have the variables switched around.

The Rhino would be the key value, and the points would have to be added into it. The example would be "Rhino : {(Point 1),(Point 2)}".

Somehow I can't get it. I can get the polyline to form, but I only get one giant line and not a multiple set of polylines based on the Rhino.

Here is the script I have written down.(re-edited to just the definition of the function)

def rhinoTracker(Rhino, X, Y, dictionary):

XYCoord = (X, Y)

   if Rhino not in dictionary:
   dictionary[Rhino]= []

dictionary[Rhino].append((XYCoord))
0 Kudos
6 Replies
DanPatterson_Retired
MVP Emeritus

Jacob...

raw encode your file paths  ie  r"c:\Your\Folder\and\file.py"  a little 'r'

If you get one big line, then you shouldn't be adding all the points to the array all at once, but break it up into rhino bits.

Maybe if you show how many points are associated with a rhino from your table it would help dissect the code

0 Kudos
JacobHorwitz1
Occasional Contributor

This the csv file it is based off of and there a re a total of 51 points.

https://www.e-education.psu.edu/geog485/sites/www.e-education.psu.edu.geog485/files/data/RhinoObserv... 

0 Kudos
DanPatterson_Retired
MVP Emeritus

first thing I would do is sort the csv based on the Rhino name (numpy, spreadsheet, whatever)

That way Tulip and Bo's points are grouped. 

Sadly, there is no temporal information so just connecting the points isn't going to work because there is no guarantee that the points were collected in sequential time.

I would bring the table into Pro as an event layer (in sorted by rhino name, or sort it in Pro).

Save to a feature class.  Split by attributes (tool) and then you can hope that the points sort spatially... if not, produce a spanning tree (my point tools on the Code Sharing site).

Of course since this is a lab... maybe everything is nicely sorted and the observer information was all on one day... this info isn't available, so I am thinking worst case scenario

have fun

JacobHorwitz1
Occasional Contributor

With the definition at least, would there need to be a variable that needs to changed around so I could have the results change to "Rhino : {(Point 1),(Point 2)}" instead of {Rhino : [(Point 1),(Point 2)]}? That been my biggest problem so far.

0 Kudos
DarrenWiens2
MVP Honored Contributor

You should be aiming for something like this:

{
  'Rhino1': [(X1, Y1), (X2, Y2), ...],
  'Rhino2': [(X1, Y1), (X2, Y2), ...],
  ...
}‍‍‍‍
JoshuaBixby
MVP Esteemed Contributor

Somehow I can't get it. I can get the polyline to form, but I only get one giant line and not a multiple set of polylines based on the Rhino.

On top of the other issues people have pointed out, what exactly do you want the output to look like?  Do you want a single, multi-part line, multiple single-part lines, or multiple multi-part lines?  And, what criteria is used to break up the features and lines into different parts.

0 Kudos