當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。