Skip to content

Instantly share code, notes, and snippets.

@NathanW2
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NathanW2/4de348da41113dbeba03 to your computer and use it in GitHub Desktop.
Save NathanW2/4de348da41113dbeba03 to your computer and use it in GitHub Desktop.
def mapselection(self):
def add_city(feature):
"""
Add a city to the output list
"""
nearCity = feature['name']
state = feature['state']
state_and_cities = "{},{}".format(nearCity, state)
lsNearCities.append(state_and_cities)
filePath = self.dlg.fileNameEdit.text()
if not filePath:
QMessageBox.warning(self.dlg, "File Name","Give it a file name and try again")
return
lsNearCities = []
layer = QgsMapLayerRegistry.instance().mapLayersByName('us_cities')[0]
selfeature = layer.selectedFeatures()
distance = self.dlg.DistancelineEdit.text()
dist = float(distance) * (1609.344)
if distance and dist != 0:
for feature in selfeature:
mbuf = feature.geometry().buffer(dist, 2)
iterFeat = layer.getFeatures()
for f in iterFeat:
geom2 = f.geometry()
if geom2.within(mbuf):
add_city(f)
else:
for feature in selfeature:
add_city(feature)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment