当前位置: 首页>>代码示例>>Python>>正文


Python QtCore.QTextCodec类代码示例

本文整理汇总了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)
开发者ID:NationalSecurityAgency,项目名称:qgis-latlontools-plugin,代码行数:84,代码来源:digitizer.py


注:本文中的qgis.PyQt.QtCore.QTextCodec类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。