Skip to main content
Solved

Writing new coordinate locations


Hi,

 

 

I'm trying to edit the locations of coordinates within an ESRI shapefile using a Python script in FME. The script appears to be working fine: the problem is that I don't know how to write the changes that the script is making to a new shapefile. In other words, my input and output shapefiles look identical, which is not what I want. 

 

 

This is what I have done so far in FME:

 

 

- read an ESRI shapefile

 

- extracted x,y coordinates from the shapefile using the CoordinateExtractor

 

- updated these coordinates using a script within the PythonCaller

 

- written a new shapefile

 

 

The Python script appears to be working properly when I check using the inspector and the Python print function (i.e. _x and _y are being updated using the setAttribute method). However, my output still looks identical to my input. How can I get the updated coordinate locations to be written to my output shapefile?

 

 

Briefly, what is stumping me is how to write a shapefile/ESRI GDB/microstation DGN containing coordinate locations that have been changed in FME.

 

 

I'm using FME Desktop ESRI Edition 2014.

 

 

Thanks very much in advance,

 

 

Tom

Best answer by david_r

Hi,

 

 

you can modify the vertices directly in the PythonCaller using the fmeobjects API, so no need to use the CoordinateExtractor or VertexCreator. Example that will shift your geometry by 1 ground unit on the X-axis and 2 ground units on the Y-axis:

 

 

---

 

def shiftCoords(feature):

 

    coords = feature.getAllCoordinates()

 

    for i in xrange(len(coords)):

 

        # Assume 2D geometries here

 

        coords[i] = (coords[i][0]+1, coords[i][1]+2)

 

    feature.resetCoords()

 

    feature.addCoordinates(coords)

 

---

 

 

David

 

 

 

View original
Did this help you find an answer to your question?
This post is closed to further activity.
It may be a question with a best answer, an implemented idea, or just a post needing no comment.
If you have a follow-up or related question, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

8 replies

takashi
Influencer
  • May 30, 2014
Hi,

 

 

The CoordinateExtractor extracts coordinates of a vertex as attribute values, but the vertex will not move even if you change the attribute values only. If the geometry type is point, you can use the VertexCreator (called 2D/3DPointReplacer in 2013 and earlier) to move it based on (_x, _y).

 

 

Takashi

  • Author
  • May 30, 2014
Thanks Takashi for the quick reply. The VertexCreator is what was missing here (I managed to dig up the 2DPointReplacer in a colleague's work). Is there a transformer that can be used to rewrite the vertices of polygons to shift them?

takashi
Influencer
  • May 30, 2014
2D/3DPointReplacer and 2D/3DPointAdder have been integrated into the VertexCreator in FME 2014.

 

But it only moves a point geometry to specified location. Since your geometry type is polygon, other approaches should be considered depending on the requirement.

 

What kind of transformation do you need?

  • Author
  • May 30, 2014
Most likely only shifting points, but I'm not entirely sure at this point, so flexilibily would be nice. The problem that I am facing is to counteract a shift in the location of annotation as it is being converted from ESRI to Microstation. Thanks again.

takashi
Influencer
  • May 31, 2014
If you need to do parallel translation of the polygon, for example, you can use the Offsetter.

david_r
Celebrity
  • Best Answer
  • June 2, 2014
Hi,

 

 

you can modify the vertices directly in the PythonCaller using the fmeobjects API, so no need to use the CoordinateExtractor or VertexCreator. Example that will shift your geometry by 1 ground unit on the X-axis and 2 ground units on the Y-axis:

 

 

---

 

def shiftCoords(feature):

 

    coords = feature.getAllCoordinates()

 

    for i in xrange(len(coords)):

 

        # Assume 2D geometries here

 

        coords[i] = (coords[i][0]+1, coords[i][1]+2)

 

    feature.resetCoords()

 

    feature.addCoordinates(coords)

 

---

 

 

David

 

 

 


gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • June 2, 2014
If you want to stick to transformers rather then diving into python & mates, the (3D)affiner offers what you need.

 

As it allows you to basicaly set up transformation matrices of all kind.

  • Author
  • June 2, 2014
Thanks everyone for the variety of approaches!

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings