from gvsig import * from geom import * def main(*args): """ Convert polygon layer to line layer with one line sort by a field """ ### INITIAL DATA path = "/home/oscm/temp/layer_ex5_01.shp" sortByField = "DISTANCE" ### LAYERS layer = currentLayer() # active layer ### PROCESS # New layer with new schema newSchema = createSchema() newSchema.append("ID", "INTEGER", size=10) newSchema.append("GEOMETRY", "GEOMETRY") CRS = currentView().getProjection() output = createShape(newSchema, path, CRS=CRS, geometryType=LINE) # Calculate lines and distance # Access to the points witho spatial orden (DISTANCE field) newLine = createLine() for feature in layer.features(sortBy=sortByField): geom = feature.geometry().centroid() newLine.addVertex(geom) values = {"ID":1, "GEOMETRY":newLine} output.append(values) # add values to output layer #Add layer to currentView. Commit changes output.commit() currentView().addLayer(output)