Skip to content

Commit

Permalink
fix migration errors
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Sep 14, 2012
1 parent ba67665 commit 5eb0111
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
8 changes: 0 additions & 8 deletions .settings/org.eclipse.core.resources.prefs

This file was deleted.

2 changes: 0 additions & 2 deletions python/plugins/sextante/.gitignore

This file was deleted.

49 changes: 49 additions & 0 deletions python/plugins/sextante/core/SextanteVectorWriter.py
@@ -0,0 +1,49 @@
from PyQt4.QtCore import *

from qgis.core import *

class SextanteVectorWriter:

MEMORY_LAYER_PREFIX = "memory:"

TYPE_MAP = {QGis.WKBPoint : "Point",
QGis.WKBLineString : "LineString",
QGis.WKBPolygon : "Polygon",
QGis.WKBMultiPoint : "MultiPoint",
QGis.WKBMultiLineString : "MultiLineString",
QGis.WKBMultiPolygon : "MultiPolygon"
}

def __init__(self, fileName, encoding, fields, geometryType, crs, options=None):
self.fileName = fileName
self.isMemory = False
self.memLayer = None
self.writer = None

if self.fileName.startswith(self.MEMORY_LAYER_PREFIX):
self.isMemory = True

uri = self.TYPE_MAP[geometryType]
if crs.isValid():
uri += "?crs=" + crs.authid()
self.memLayer = QgsVectorLayer(uri, self.fileName, "memory")
self.writer = self.memLayer.dataProvider()
self.writer.addAttributes(fields.values())
self.memLayer.updateFieldMap()
else:
formats = QgsVectorFileWriter.supportedFiltersAndFormats()
OGRCodes = {}
for key, value in formats.items():
extension = str(key)
extension = extension[extension.find('*.') + 2:]
extension = extension[:extension.find(" ")]
OGRCodes[extension] = value

extension = self.fileName[self.fileName.find(".") + 1:]
self.writer = QgsVectorFileWriter(self.fileName, encoding, fields, geometryType, crs, OGRCodes[extension])

def addFeature(self, feature):
if self.isMemory:
self.writer.addFeatures([feature])
else:
self.writer.addFeature(feature)

0 comments on commit 5eb0111

Please sign in to comment.