本文整理汇总了Python中qgis.PyQt.QtCore.QTextCodec类的典型用法代码示例。如果您正苦于以下问题:Python QTextCodec类的具体用法?Python QTextCodec怎么用?Python QTextCodec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTextCodec类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addFeature
def addFeature(self):
text = self.lineEdit.text().strip()
if text == "":
return
layer = self.iface.activeLayer()
if layer == None:
return
try:
if (self.inputProjection == 0) or (text[0] == '{'):
# If this is GeoJson it does not matter what inputProjection is
if text[0] == '{': # This may be a GeoJSON point
codec = QTextCodec.codecForName("UTF-8")
fields = QgsJsonUtils.stringToFields(text, codec)
fet = QgsJsonUtils.stringToFeatureList(text, fields, codec)
if (len(fet) == 0) or not fet[0].isValid():
raise ValueError('Invalid Coordinates')
geom = fet[0].geometry()
if geom.isEmpty() or (geom.wkbType() != QgsWkbTypes.Point):
raise ValueError('Invalid GeoJSON Geometry')
pt = geom.asPoint()
lat = pt.y()
lon = pt.x()
elif re.search(r'POINT\(', text) != None:
m = re.findall(r'POINT\(\s*([+-]?\d*\.?\d*)\s+([+-]?\d*\.?\d*)', text)
if len(m) != 1:
raise ValueError('Invalid Coordinates')
lon = float(m[0][0])
lat = float(m[0][1])
else:
lat, lon = LatLon.parseDMSString(text, self.inputXYOrder)
srcCrs = epsg4326
elif self.inputProjection == 1:
# This is an MGRS coordinate
text = re.sub(r'\s+', '', unicode(text)) # Remove all white space
lat, lon = mgrs.toWgs(text)
srcCrs = epsg4326
elif self.inputProjection == 4:
text = text.strip()
coord = olc.decode(text)
lat = coord.latitudeCenter
lon = coord.longitudeCenter
srcCrs = epsg4326
else: # Is either the project or custom CRS
if re.search(r'POINT\(', text) == None:
coords = re.split(r'[\s,;:]+', text, 1)
if len(coords) < 2:
raise ValueError('Invalid Coordinates')
if self.inputXYOrder == 0: # Y, X Order
lat = float(coords[0])
lon = float(coords[1])
else:
lon = float(coords[0])
lat = float(coords[1])
else:
m = re.findall(r'POINT\(\s*([+-]?\d*\.?\d*)\s+([+-]?\d*\.?\d*)', text)
if len(m) != 1:
raise ValueError('Invalid Coordinates')
lon = float(m[0][0])
lat = float(m[0][1])
if self.inputProjection == 2: # Project CRS
srcCrs = self.canvas.mapSettings().destinationCrs()
else:
srcCrs = QgsCoordinateReferenceSystem(self.inputCustomCRS)
except:
#traceback.print_exc()
self.iface.messageBar().pushMessage("", "Invalid Coordinate" , level=Qgis.Warning, duration=2)
return
self.lineEdit.clear()
caps = layer.dataProvider().capabilities()
if caps & QgsVectorDataProvider.AddFeatures:
destCRS = layer.crs() # Get the CRS of the layer we are adding a point toWgs
transform = QgsCoordinateTransform(srcCrs, destCRS, QgsProject.instance())
# Transform the input coordinate projection to the layer CRS
x, y = transform.transform(float(lon), float(lat))
feat = QgsFeature(layer.fields())
feat.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(x, y)))
if layer.fields().count() == 0:
layer.addFeature(feat)
self.lltools.zoomTo(srcCrs, lat, lon)
else:
if self.iface.openFeatureForm(layer, feat):
layer.addFeature(feat)
self.lltools.zoomTo(srcCrs, lat, lon)