本文整理汇总了Python中utilities.writeShape函数的典型用法代码示例。如果您正苦于以下问题:Python writeShape函数的具体用法?Python writeShape怎么用?Python writeShape使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了writeShape函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: testWrite
def testWrite(self):
"""Check we can write a vector file."""
self.mMemoryLayer = QgsVectorLayer(
('Point?crs=epsg:4326&field=name:string(20)&'
'field=age:integer&field=size:double&index=yes'),
'test',
'memory')
assert self.mMemoryLayer is not None, 'Provider not initialized'
myProvider = self.mMemoryLayer.dataProvider()
assert myProvider is not None
ft = QgsFeature()
ft.setGeometry(QgsGeometry.fromPoint(QgsPoint(10, 10)))
ft.setAttributes(['Johny', 20, 0.3])
myResult, myFeatures = myProvider.addFeatures([ft])
assert myResult
assert len(myFeatures) > 0
writeShape(self.mMemoryLayer, 'writetest.shp')
开发者ID:dudds6699,项目名称:QGIS,代码行数:20,代码来源:test_qgsvectorfilewriter.py
示例2: testWrite
def testWrite(self):
"""Check we can write a vector file."""
self.mMemoryLayer = QgsVectorLayer(
("Point?crs=epsg:4326&field=name:string(20)&" "field=age:integer&field=size:double&index=yes"),
"test",
"memory",
)
self.assertIsNotNone(self.mMemoryLayer, "Provider not initialized")
myProvider = self.mMemoryLayer.dataProvider()
self.assertIsNotNone(myProvider)
ft = QgsFeature()
ft.setGeometry(QgsGeometry.fromPoint(QgsPoint(10, 10)))
ft.setAttributes(["Johny", 20, 0.3])
myResult, myFeatures = myProvider.addFeatures([ft])
self.assertTrue(myResult)
self.assertTrue(myFeatures)
writeShape(self.mMemoryLayer, "writetest.shp")
开发者ID:liminlu0314,项目名称:QGIS,代码行数:20,代码来源:test_qgsvectorfilewriter.py
示例3: testWrite
def testWrite(self):
"""Check we can write a vector file."""
self.mMemoryLayer = QgsVectorLayer(
("Point?crs=epsg:4326&field=name:string(20)&" "field=age:integer&field=size:double&index=yes"),
"test",
"memory",
)
assert self.mMemoryLayer is not None, "Provider not initialised"
myProvider = self.mMemoryLayer.dataProvider()
assert myProvider is not None
ft = QgsFeature()
ft.setGeometry(QgsGeometry.fromPoint(QgsPoint(10, 10)))
ft.setAttributeMap({0: QVariant("Johny"), 1: QVariant(20), 2: QVariant(0.3)})
myResult, myFeatures = myProvider.addFeatures([ft])
assert myResult == True
assert len(myFeatures) > 0
writeShape(self.mMemoryLayer, "writetest.shp")
开发者ID:Nald,项目名称:Quantum-GIS,代码行数:20,代码来源:test_qgsvectorfilewriter.py
示例4: testClipping
def testClipping(self):
"""Test that we can clip geometries using other geometries."""
myMemoryLayer = QgsVectorLayer(
('LineString?crs=epsg:4326&field=name:string(20)&index=yes'),
'clip-in',
'memory')
assert myMemoryLayer is not None, 'Provider not initialised'
myProvider = myMemoryLayer.dataProvider()
assert myProvider is not None
myFeature1 = QgsFeature()
myFeature1.setGeometry(QgsGeometry.fromPolyline([
QgsPoint(10,10),
QgsPoint(20,10),
QgsPoint(30,10),
QgsPoint(40,10),
]
))
myFeature1.setAttributes([QVariant('Johny')])
myFeature2 = QgsFeature()
myFeature2.setGeometry(QgsGeometry.fromPolyline([
QgsPoint(10,10),
QgsPoint(20,20),
QgsPoint(30,30),
QgsPoint(40,40),
]
))
myFeature2.setAttributes([QVariant('Be')])
myFeature3 = QgsFeature()
myFeature3.setGeometry(QgsGeometry.fromPolyline([
QgsPoint(10,10),
QgsPoint(10,20),
QgsPoint(10,30),
QgsPoint(10,40),
]
))
myFeature3.setAttributes([QVariant('Good')])
myResult, myFeatures = myProvider.addFeatures(
[myFeature1, myFeature2, myFeature3])
assert myResult == True
assert len(myFeatures) == 3
myClipPolygon = QgsGeometry.fromPolygon([[
QgsPoint(20,20),
QgsPoint(20,30),
QgsPoint(30,30),
QgsPoint(30,20),
QgsPoint(20,20),
]]
)
print 'Clip: %s' % myClipPolygon.exportToWkt()
writeShape(myMemoryLayer, 'clipGeometryBefore.shp')
fit = myProvider.getFeatures()
myFeatures = []
myFeature = QgsFeature()
while fit.nextFeature(myFeature):
myGeometry = myFeature.geometry()
if myGeometry.intersects(myClipPolygon):
# Adds nodes where the clip and the line intersec
myCombinedGeometry = myGeometry.combine(myClipPolygon)
# Gives you the areas inside the clip
mySymmetricalGeometry = myGeometry.symDifference(
myCombinedGeometry)
# Gives you areas outside the clip area
# myDifferenceGeometry = myCombinedGeometry.difference(
# myClipPolygon)
#print 'Original: %s' % myGeometry.exportToWkt()
#print 'Combined: %s' % myCombinedGeometry.exportToWkt()
#print 'Difference: %s' % myDifferenceGeometry.exportToWkt()
print 'Symmetrical: %s' % mySymmetricalGeometry.exportToWkt()
myExpectedWkt = 'LINESTRING(20.0 20.0, 30.0 30.0)'
# There should only be one feature that intersects this clip
# poly so this assertion should work.
self.assertEqual(myExpectedWkt,
mySymmetricalGeometry.exportToWkt())
myNewFeature = QgsFeature()
myNewFeature.setAttributes(myFeature.attributes())
myNewFeature.setGeometry(mySymmetricalGeometry)
myFeatures.append(myNewFeature)
myNewMemoryLayer = QgsVectorLayer(
('LineString?crs=epsg:4326&field=name:string(20)&index=yes'),
'clip-out',
'memory')
myNewProvider = myNewMemoryLayer.dataProvider()
myResult, myFeatures = myNewProvider.addFeatures(myFeatures)
self.assertTrue(myResult)
self.assertEqual(len(myFeatures), 1)
writeShape(myNewMemoryLayer, 'clipGeometryAfter.shp')
开发者ID:alexgleith,项目名称:Quantum-GIS,代码行数:97,代码来源:test_qgsgeometry.py
注:本文中的utilities.writeShape函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论