Skip to main content
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
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
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?
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?
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.
If you need to do parallel translation of the polygon, for example, you can use the Offsetter.
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

 

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

 

    feature.resetCoords()

 

    feature.addCoordinates(coords)

 

---

 

 

David

 

 

 


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.
Thanks everyone for the variety of approaches!

Reply