Skip to main content
deleted 30 characters in body
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

I have some features selected by using "Select Features by Freehand" tool in QGIS and try to find the buffer for those selected features alone and write the city and state names within in the buffer to a csv file. My code and image is attached for a clear understanding. it is writing an csv file in the given location but nothing is found inside the csv.Any help would be appreciated.

enter image description here

And my code is

import csv
selection = layer.selectedFeatures()
layer = qgis.utils.iface.activeLayer()
columns=['name', 'state' ]
for feature in selection:
  mbuf = feature.geometry().buffer(50, 2)
  iterFeat = layer.getFeatures()
  for f in iterFeat:
    geom2 = f.geometry()
    valTest = QgsGeometry.within(geom2, mbuf)
    lsNearCities = []
    if valTest:
        idx = selection.fieldNameIndex('name')
        idx1 = selection.fieldNameIndex('state')
        nearCity = f.attributes()[idx]
        state = f.attributes()[idx1]
        state_and_cities = str(state) + "," + nearCity
        lsNearCities.append(state_and_cities)
        print lsNearCities

I have some features selected by using "Select Features by Freehand" tool in QGIS and try to find the buffer for those selected features alone and write the city and state names within in the buffer to a csv file. My code and image is attached for a clear understanding. it is writing an csv file in the given location but nothing is found inside the csv.Any help would be appreciated.

enter image description here

And my code is

import csv
selection = layer.selectedFeatures()
layer = qgis.utils.iface.activeLayer()
columns=['name', 'state' ]
for feature in selection:
  mbuf = feature.geometry().buffer(50, 2)
  iterFeat = layer.getFeatures()
  for f in iterFeat:
    geom2 = f.geometry()
    valTest = QgsGeometry.within(geom2, mbuf)
    lsNearCities = []
    if valTest:
        idx = selection.fieldNameIndex('name')
        idx1 = selection.fieldNameIndex('state')
        nearCity = f.attributes()[idx]
        state = f.attributes()[idx1]
        state_and_cities = str(state) + "," + nearCity
        lsNearCities.append(state_and_cities)
        print lsNearCities

I have some features selected by using "Select Features by Freehand" tool in QGIS and try to find the buffer for those selected features alone and write the city and state names within in the buffer to a csv file. My code and image is attached for a clear understanding. it is writing an csv file in the given location but nothing is found inside the csv.

enter image description here

And my code is

import csv
selection = layer.selectedFeatures()
layer = qgis.utils.iface.activeLayer()
columns=['name', 'state' ]
for feature in selection:
  mbuf = feature.geometry().buffer(50, 2)
  iterFeat = layer.getFeatures()
  for f in iterFeat:
    geom2 = f.geometry()
    valTest = QgsGeometry.within(geom2, mbuf)
    lsNearCities = []
    if valTest:
        idx = selection.fieldNameIndex('name')
        idx1 = selection.fieldNameIndex('state')
        nearCity = f.attributes()[idx]
        state = f.attributes()[idx1]
        state_and_cities = str(state) + "," + nearCity
        lsNearCities.append(state_and_cities)
        print lsNearCities
deleted 137 characters in body
Source Link
User123
  • 3k
  • 3
  • 37
  • 67

I have some features selected by using "Select Features by Freehand" tool in QGIS and try to find the buffer for those selected features alone and write the city and state names within in the buffer to a csv file. My code and image is attached for a clear understanding. it is writing an csv file in the given location but nothing is found inside the csv.Any help would be appreciated.

enter image description here

And my code is

import csv
selection = layer.selectedFeatures()
layer = qgis.utils.iface.activeLayer()
columns=['name', 'state' ]
for feature =in layer.selectedFeatures()selection:
  mbuf = feature.geometry().buffer(50, 2)
  iterFeat = layer.getFeatures()
  for f in iterFeat:
    geom2 = f.geometry()
    valTest = QgsGeometry.within(geom2, mbuf)
    lsNearCities = []
    if valTest:
        idx = layerselection.fieldNameIndex('name')
        idx1 = layerselection.fieldNameIndex('state')
        nearCity = f.attributes()[idx]
        state = f.attributes()[idx1]
        state_and_cities = str(state) + "," + nearCity
    lsNearCities.append(state_and_cities)
    filteredFields = []
    for feature in features:
        attrs = lsNearCities
    with open('E:/Kcube/test2.csv', 'w') as csvfile:
       writer = csv.writerappend(csvfile, delimiter=','state_and_cities)
       for field in filteredFields:
      print writer.writerow(field)lsNearCities

I have some features selected by using "Select Features by Freehand" tool in QGIS and try to find the buffer for those selected features alone and write the city and state names within in the buffer to a csv file. My code and image is attached for a clear understanding. it is writing an csv file in the given location but nothing is found inside the csv.Any help would be appreciated.

enter image description here

And my code is

import csv
layer = qgis.utils.iface.activeLayer()
feature = layer.selectedFeatures()
mbuf = feature.geometry().buffer(50, 2)
iterFeat = layer.getFeatures()
for f in iterFeat:
  geom2 = f.geometry()
  valTest = QgsGeometry.within(geom2, mbuf)
  if valTest:
    idx = layer.fieldNameIndex('name')
    idx1 = layer.fieldNameIndex('state')
    nearCity = f.attributes()[idx]
    state = f.attributes()[idx1]
    state_and_cities = str(state) + "," + nearCity
    lsNearCities.append(state_and_cities)
    filteredFields = []
    for feature in features:
        attrs = lsNearCities
    with open('E:/Kcube/test2.csv', 'w') as csvfile:
       writer = csv.writer(csvfile, delimiter=',')
       for field in filteredFields:
       writer.writerow(field)

I have some features selected by using "Select Features by Freehand" tool in QGIS and try to find the buffer for those selected features alone and write the city and state names within in the buffer to a csv file. My code and image is attached for a clear understanding. it is writing an csv file in the given location but nothing is found inside the csv.Any help would be appreciated.

enter image description here

And my code is

import csv
selection = layer.selectedFeatures()
layer = qgis.utils.iface.activeLayer()
columns=['name', 'state' ]
for feature in selection:
  mbuf = feature.geometry().buffer(50, 2)
  iterFeat = layer.getFeatures()
  for f in iterFeat:
    geom2 = f.geometry()
    valTest = QgsGeometry.within(geom2, mbuf)
    lsNearCities = []
    if valTest:
        idx = selection.fieldNameIndex('name')
        idx1 = selection.fieldNameIndex('state')
        nearCity = f.attributes()[idx]
        state = f.attributes()[idx1]
        state_and_cities = str(state) + "," + nearCity
        lsNearCities.append(state_and_cities)
        print lsNearCities
deleted 1 character in body
Source Link
User123
  • 3k
  • 3
  • 37
  • 67

I have some features selected by using "Select Features by Freehand" tool in QGIS and try to find the buffer for those selected features alone and write the city and state names within in the buffer to a csv file. My code and image is attached for a clear understanding. it is writing an csv file in the given location but nothing is found inside the csv.Any help would be appreciated.

enter image description here

And my code is

import csv
layer = qgis.utils.iface.activeLayer()
featuresfeature = layer.selectedFeatures()
mbuf = feature.geometry().buffer(50, 2)
iterFeat = layer.getFeatures()
for f in iterFeat:
  geom2 = f.geometry()
  valTest = QgsGeometry.within(geom2, mbuf)
  if valTest:
    idx = layer.fieldNameIndex('name')
    idx1 = layer.fieldNameIndex('state')
    nearCity = f.attributes()[idx]
    state = f.attributes()[idx1]
    state_and_cities = str(state) + "," + nearCity
    lsNearCities.append(state_and_cities)
    filteredFields = []
    for feature in features:
        attrs = lsNearCities
    with open('E:/Kcube/test2.csv', 'w') as csvfile:
       writer = csv.writer(csvfile, delimiter=',')
       for field in filteredFields:
       writer.writerow(field)

I have some features selected by using "Select Features by Freehand" tool in QGIS and try to find the buffer for those selected features alone and write the city and state names within in the buffer to a csv file. My code and image is attached for a clear understanding. it is writing an csv file in the given location but nothing is found inside the csv.Any help would be appreciated.

enter image description here

And my code is

import csv
layer = qgis.utils.iface.activeLayer()
features = layer.selectedFeatures()
mbuf = feature.geometry().buffer(50, 2)
iterFeat = layer.getFeatures()
for f in iterFeat:
  geom2 = f.geometry()
  valTest = QgsGeometry.within(geom2, mbuf)
  if valTest:
    idx = layer.fieldNameIndex('name')
    idx1 = layer.fieldNameIndex('state')
    nearCity = f.attributes()[idx]
    state = f.attributes()[idx1]
    state_and_cities = str(state) + "," + nearCity
    lsNearCities.append(state_and_cities)
    filteredFields = []
    for feature in features:
        attrs = lsNearCities
    with open('E:/Kcube/test2.csv', 'w') as csvfile:
       writer = csv.writer(csvfile, delimiter=',')
       for field in filteredFields:
       writer.writerow(field)

I have some features selected by using "Select Features by Freehand" tool in QGIS and try to find the buffer for those selected features alone and write the city and state names within in the buffer to a csv file. My code and image is attached for a clear understanding. it is writing an csv file in the given location but nothing is found inside the csv.Any help would be appreciated.

enter image description here

And my code is

import csv
layer = qgis.utils.iface.activeLayer()
feature = layer.selectedFeatures()
mbuf = feature.geometry().buffer(50, 2)
iterFeat = layer.getFeatures()
for f in iterFeat:
  geom2 = f.geometry()
  valTest = QgsGeometry.within(geom2, mbuf)
  if valTest:
    idx = layer.fieldNameIndex('name')
    idx1 = layer.fieldNameIndex('state')
    nearCity = f.attributes()[idx]
    state = f.attributes()[idx1]
    state_and_cities = str(state) + "," + nearCity
    lsNearCities.append(state_and_cities)
    filteredFields = []
    for feature in features:
        attrs = lsNearCities
    with open('E:/Kcube/test2.csv', 'w') as csvfile:
       writer = csv.writer(csvfile, delimiter=',')
       for field in filteredFields:
       writer.writerow(field)
Source Link
User123
  • 3k
  • 3
  • 37
  • 67
Loading