How to identify city names from shapefiles with coordinate bounds provided

I have urban sprawl shapefiles showing the urban expansion cities across the US. However, the attribute table does not provide city names or zip codes. Only city bounds are available in the form of polygons in the shapefile. Is it possible to identify particular city names that surround the urban areas from the available shapefile based on the urban lat-long bounds of the polygons?

1 Comment

I wonder if you're going to run into problems similar to those with the old XKCD color name survey, where different people may call a region by different names.
For example, would there be people reviewing your work who would be offended if you labeled one of the boroughs of New York City as just "New York City"? Or would that cause problems for your analysis if in one place you labeled a polygon as Brooklyn and in another labeled it as NYC?

Sign in to comment.

 Accepted Answer

One would have to have the coordinates of the cities with their names as an auxiliary database. The MATLAB Mapping Toolbox <contains one such file for 318 world populated places>; if your locations are one of those, it should be simple enough to determine which is contained within the boundaries you have. If it isn't, then you'll be out of luck.

13 Comments

OK. If this matches, how to identify common polygon layers in that shapefile that belong to these cities. Will any table join features work to map polygon layer with point shapefile? Please do suggest, any example script would help.
OK, but if my matrix size is 1000 for polygon shapefile but world mega cities are of size only around 300, how to map this disimilar arrays?
You'll have to see if any of the 300 is in the list of 1000. I think it will take a double loop as isinterior requires a single polyval shape.
I don't have the Mapping TB so don't have any direct experience; only reading the doc.
If you expect somebody to write code, post a small working example of the data you have (a very small sample is sufficient, no need for the whole thing) and somebody with actual experience may chime in. Having to also create example datafiles besides is asking a lot of the volunteers here...
ADDENDUM
"... it will take a double loop ..."
The documentation examples vectorize the use of isinterior by having the ROIs being looked into inside one object as disjoint areas; whether the data you have could be turned into such a structure I don't know; I have no experience in the area and without an example of what you do have, hands are pretty-much tied...
"... 1000 for polygon shapefile but world mega cities are of size only around 300, ..."
The key is that unless all 1000 contain one of the given 300+, you have no information with which to be able to identify them; you would have to have an augmented list of locations with those locations identified within it in order to be able to do so.
I'm sure such databases exist, but they're not supplied with MATLAB by The Mathworks...
The polygons are from other source - I need to identify if any of these cities belong to this polygons.
Yes, you said that already...the problem still remains, you will have to obtain a database that includes all the given areas in it by location and name in order to be able to complete the task.
What is in the MATLAB Mapping TB is a worldwide list of some 300+ major metropolitan areas, but it certainly won't include all the myriad of areas around US cities.
Without such an augmented file, the task is simply not possible to complete; you probably can find a small subset of the 1000 in the 300, but that will be all.
I wonder if it would work to connect to google maps and ask for location information ?
https://www.kaggle.com/datasets/sergejnuss/united-states-cities-database might be a database to start with, although @Poulomi should be as able to gargle search as well as you and I can...
In GIS such kind of functionalities seems exist, where open street map can be invoked at the background of shapefile and city location can be identified. However, it is not clear if MATLAB has such functionality. Nevertheless, I have the shape files - I just need to identify urban agglomerates (polygon), which may be the part of particular city. For this, the lat-long extent of cities should suffice, if that fall on that partcular polygon to indentify specific urban agglomerates.
Again, the tools are there, but the specific functionality you're looking for is not implemented directly as with a dedicated GIS system that has its own database of locations and is tied to the location of the device or an input user value. That doesn't just happen by magic; somebody wrote a lot of code and there's a lot of firmware and hardware making that happen so apparently easily. Looks are deceiving.
The first problem here is still that MATLB does not include a builtin list of the locations of all the municipalities in the US in order to be able to ascertain what is the location of the polygon of interest -- only the small(ish) global list.
The file at the link I posted above has something approaching 30,000 US locations in it; your mission, should you choose to accept it, is to use those centroids with isinterior to identify them (the municipality to which the polygon belongs)*.
As I pointed out earlier, with the data structure of one ROI polygon per element, it will take a nested loop to iterate over the polygons with each of the location coordinates. If you could first create a composite of the ROIs as one polyval object, then the lookup could be for each location in turn over a single loop. In practice, it would likely be about as effective to do the double loop directly as to build the composite object over which isinterior will then iterate over internally, anyways.
MATLAB has ways to interact with web services, but I'd expect that to be quite slow in comparison to a direct search and you will have to locate a suitable web server that has the particular service you're needing and figure out how to interact with it.
(*) This, then, likely will also not suffice to answer the question you've posed in that knowing that some place is identified as being within a given polygon may tell you what the name of that suburb is, but it still won't tell you which larger metropolitan areay/city it is a suburb of...and, of course, there is not unique set of names of such entities in each city, there can and are duplicates there. One would have to find or somehow create the list of "proximate to" cities for each of these individual entities. I suppose that has also been done somewhere...
Thanks, I will work on it and get back if I have any further queries on double looping.

Sign in to comment.

More Answers (0)

Products

Release

R2022b

Asked:

on 5 Jul 2025

Commented:

on 8 Jul 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!