Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a shapefile whose features I can filter by specifying a where clause in the query dialogue. F.x. I have a field named 'city_name' and by stating 'city_name = "London"' in the where clause only London is displayed. What I would like to do now is to fetch all values in 'city_name' from the attribute table.

Something like that:

select distinct city_name from [attribute table]

I found several tools in QGIS apparently dealing with SQL and I also had a quick look at the different Plugins. But I fail at connecting to a database or the table name ... what database or which table in that case?

In the end I want to export the result list and use it for further processing.

(Am using QuantumGIS 1.8)

share|improve this question
add comment

3 Answers

up vote 8 down vote accepted

You have a few choices to do what you ask.

1 - Import your shapefile in a Spatialite or Postgis database, and then you can query your table using complete SQL statements;

2 - Use the Dissolve tool (Vector > Geoprocessing Tools > Dissolve), to dissolve your shapefiles using the field "city_name". Although is an strange method, the dbf file of the resulting shapefile will provide the list you need;

3 - Take a look at group stats plugin (1.6), you can use "city_name" as classification field, and press calculate. It will calculate some stats about each city, you can then copy the result and extract the city list.

Hope it helps.

Update:

I have just noticed that, in the Vector > Analysis Tools, there is a List unique Values tool that is precisely what one needs for this task. So easy... no workarounds and no need for Plugins.

share|improve this answer
    
#3 did the trick! –  Raffael Jan 27 '13 at 19:30
add comment

Try including something like:

where city_name is NOT NULL or not equal to NULL

share|improve this answer
    
1  
this will lead to QGIS displaying all features with a city_name. but I want to export the city_name values. –  Raffael Jan 27 '13 at 19:15
add comment

Use query builder in qgis, go to city name field in fields in query builder. Go to values, add all. delete any nulls. build a script similar to city name = "london" and city name = "paris" untill you have the complete list of names and run the script. Now all city names are selected. you can export selected as a shape file and import into a postgresql database. To use a postgresql backend to qgis install a postgresql stack with geoserver, postgresql, and a postgis enabled databse in the postgresql. Store your data as post gis in the postgis database. You will need to connect to server. play around a bit and you will figure it out.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.