[Qgis-developer] Poligon coordinates in PyQgis 2

gene martin.laloux at gmail.com
Thu Oct 17 23:45:20 PDT 2013


in the same way as before but with layer.getFeatures():

        layer = qgis.utils.iface.activeLayer()
        for elem in layer.getFeatures():
                geom= elem.geometry()
                poly = geom.asPolygon()

       poly.wkbType() == QGis.WKBPolygon
       True
       # coordinates of vertex:
       print poly
       [[(232139,110988), (232673,110410), (232311,110090), (231814,110190),
(231684,110648), (232139,110988)]].

There are other ways as the result of getFeatures() is now a generator:

       layer = qgis.utils.iface.activeLayer()
       elem = layer.getFeatures().next()
       geom= elem.geometry()
       geom.exportToGeoJSON()
       u'{ "type": "Polygon", "coordinates": [ [ [232139.36700053617823869,
110988.40261790754448157], [232672.76215034080087207,
110409.80448930594138801], [232311.13831996478256769,
110090.37010580713103991], [231813.90555319777922705,
110189.81665916054043919], [231684.3236806463683024,
110647.87351097013743129], [232139.36700053617823869,
110988.40261790754448157] ] ] }'





--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Poligon-coordinates-in-PyQgis-2-tp5084165p5084343.html
Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.


More information about the Qgis-developer mailing list