[common] Extend City<T> with country, AdminRegion and type; enrich cities.xml#189
[common] Extend City<T> with country, AdminRegion and type; enrich cities.xml#189comoglu wants to merge 8 commits into
Conversation
| std::string _countryID; | ||
| double _population; | ||
| std::string _category; | ||
| std::string _type; |
There was a problem hiding this comment.
Wouldn't a type enumeration be a better approach? Is there a defined set of values for type?
There was a problem hiding this comment.
Good point @gempa-jabe the values are indeed fixed. GeoNames feature codes map to exactly four types: city (PPLC/PPLA/PPLA2), town (PPL/PPLA3/PPLA4), village (PPLF/PPLL/PPLR etc.) and suburb (PPLX), plus Unknown for entries where the attribute is absent.
I've replaced the std::string with a CityType enum class and added parseCityType()/toString() helpers for the XML round-trip. The cities.xml format is unchanged — serialization still uses the lowercase string attribute, so there's no migration needed
comoglu@2b7623a
|
I would be interested in how big that will grow. Given all the redundancy of state and type and also country cannot be for free. I haven't checked but maybe there is already a standard out there to describe such administrative information. |
|
15MB |
|
OK, that is not too much of a difference. The schema itself would be something I would like to address. I personally am not a big fan of "stateFull" which is actually "state". Unfortunately I do not have the time right now. |
|
Thanks for the feedback. To address the stateFull naming concern: in the updated implementation I have already replaced both state and stateFull flat strings with a dedicated AdminRegion that has two clear fields — abbr (ISO 3166-2 suffix, like. "NSW") and name (full subdivision name, e.g. "New South Wales"). This serializes as a child element: New South Wales |
|
Updating Cities xml for entire world in one rule is indeed a hard work. |
|
I've shared the enriched cities.xml as a preview. Enriching city types globally with a single rule set is harder than I would expect — GeoNames feature codes are inconsistently applied (e.g. a 1M+ population city classified as PPL → "town" based on natural earth data (shape file)). Before going further, I'd appreciate your direction: Is the type field worth pursuing, or should I drop it ? |
Addresses @Jabe request in PR SeisComP#189: the location type was a free std::string accepting any value, but the set of valid values derived from GeoNames feature codes is fixed and well-defined. Introduce a CityType enum class (Unknown, City, Town, Village, Suburb) together with parseCityType()/toString() helpers. Serialization still uses the lowercase string form in XML so cities.xml requires no changes.
Addresses @gempa-jabe request in PR SeisComP#189: the location type was a free std::string accepting any value, but the set of valid values derived from GeoNames feature codes is fixed and well-defined. Introduce a CityType enum class (Unknown, City, Town, Village, Suburb) together with parseCityType()/toString() helpers. Serialization still uses the lowercase string form in XML so cities.xml requires no changes.
4a08572 to
2b7623a
Compare
|
Actually I do not have strong feelings about it. Maybe we can start extending the city model with the new attributes. You can then test and optimize your |
2b7623a to
66f68fc
Compare
|
|
||
| // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| void AdminRegion::serialize(Core::BaseObject::Archive& ar) { | ||
| abbr = ""; name = ""; |
There was a problem hiding this comment.
If you would write an object, it would reset your attributes. Maybe checking isReading() could help in that regard. Why would you want to do that anyway? Is there any use-case you have in mind requiring this reset?
There was a problem hiding this comment.
You're right, I just followed the same pattern already in the file. Since the strings default to empty I'll remove it. Should the pre-existing resets in City::serialize() be cleaned up as well or leave them as-is?
There was a problem hiding this comment.
I will remove them in the main branch as this is just wrong. Since we are just reading those classes, it might not be important but it is still wrong.
I agree that makes sense. The model extensions (country, AdminRegion and CityType) are already in this PR. I can split the updated cities.xml into a separate PR. Do you think then this PR can be merged after you finish reviewing it. That also gives me time to test and optimise the data locally before submitting it. For future attributes, elevation could be a natural addition to the dataset. I'll think about what else might be useful during local testing. |
Yep, this is actually just an extension to the current model. |
Great, thanks. |
city.type() now returns a CityType enum wrapper (MAKEENUM) rather than std::string following the change in SeisComP/common#189.
| void City<T>::serialize(Core::BaseObject::Archive& ar) { | ||
| NamedCoord<T>::serialize(ar); | ||
| _category = ""; _countryID = ""; _country = ""; _type = ""; | ||
| _category = ""; _countryID = ""; _country = ""; _type = CITYTYPE_UNKNOWN; |
There was a problem hiding this comment.
Please remove that as well.
There was a problem hiding this comment.
I have removed all other occurrences with e3a8924.
Two new options for controlling the map view when an event arrives, applied in priority order: 1. display.lonmin/max/latmin/max (already existing) — if set, the map is anchored to that region on every event popup, regardless of where the event is located. Useful for regional networks monitoring a fixed area (e.g. an scesv alias per region). 2. display.defaultEventRadius — configurable radius in degrees, centred on the event epicentre (mirrors olv.map.event.defaultRadius in scolv). A negative value (default) restores the original automatic behaviour of using the maximum arrival distance capped at 30 degrees. If neither option is set the existing behaviour is fully preserved.
Extends the City<T> template class with three new optional attributes
to carry richer location metadata sourced from GeoNames and Natural Earth:
type — location type, e.g. "city", "town", "village", "suburb"
state — ISO 3166-2 alphabetic subdivision abbreviation, e.g. "NSW", "CA"
Only present for countries that use alphabetic codes.
stateFull — full administrative region name, e.g. "New South Wales"
All three fields are serialized as XML attributes (NAMED_OBJECT),
consistent with the existing countryID and category fields. They default
to empty strings and are fully backwards-compatible — existing cities.xml
files without these attributes parse without error.
This allows applications such as scolv to display type and state
information via SCApp->cities() without requiring a separate supplementary
locations file.
- City<T>: add country() / setCountry() serialised as <country> child element
- City<T>: replace state/stateFull strings with AdminRegion { abbr, name }
serialised as <state abbr="NSW"><name>New South Wales</name></state>
- Document fixed type values: city, town, village, suburb
- Regenerate cities.xml with country names (Natural Earth), admin region
(ISO 3166-2 abbreviation + full name via NE admin1 shapefile), and type
(GeoNames feature codes); 70242 country names, 71654 states, 56860 types
Replace the manual enum class and custom string conversion with MAKEENUM as suggested by @gempa-jabe. The archive now handles string serialization automatically.
std::string members default to empty so the explicit reset is redundant and would corrupt data on write.
CityType and AdminRegion are optional in cities.xml; using plain types caused the archive to mark the entire City object invalid when those attributes/elements were absent, silently dropping all cities. Wrap both fields in OPT() (std::optional) so the archive skips missing fields gracefully. type() and adminRegion() return safe defaults when the optional is not set.
5f11d4a to
6be58f4
Compare
city.type() now returns a CityType enum wrapper (MAKEENUM) rather than std::string following the change in SeisComP/common#189.
|
Rebased onto current main to incorporate upstream commit |
|
One minor change request: Could please use American English in your source code as well as in the package documentation and description.xml files. |
Replace British spellings: honoured→honored, unrecognised→unrecognized, centre→center.
|
Done
…On Thu, 30 Apr 2026 at 11:29 pm, Stephan Herrnkind ***@***.***> wrote:
*gempa-stephan* left a comment (SeisComP/common#189)
<#189 (comment)>
One minor change request: Could please use American English
<https://docs.gempa.de/seiscomp/current/base/style-guide.html#english-language>
in your source code as well as in the package documentation and
description.xml files.
—
Reply to this email directly, view it on GitHub
<#189 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACB5ZSDKCX6MQPEJPR6PPEL4YNIKPAVCNFSM6AAAAACXXBBMAGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DGNJSHA3DAOJSG4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
city.type() now returns a CityType enum wrapper (MAKEENUM) rather than std::string following the change in SeisComP/common#189.
Extends
City<T>with three new fields to enable richer location descriptions in SeisComP applications.Changes
AdminRegionstruct (replaces flatstate/stateFullstrings)A dedicated struct serialised as a child element:
abbr— ISO 3166-2 alphabetic subdivision suffix (e.g.NSW,CA); empty where only numeric codes exist (e.g. Japan, China, Türkiye)name— full subdivision namecountryfieldFull English country name serialised as a
<country>child element:Allows applications to display a human-readable country name without maintaining a separate ISO A2 → name lookup table.
typefieldLocation type derived from GeoNames feature codes. One of (or empty if unknown):
citytownvillagesuburbUpdated
cities.xmlRe-enriched from freely available sources:
countryIDcountryne_10m_admin_0_countries)statene_10m_admin_1_states_provinces(ISO 3166-2 abbreviations)typecities500.txtfeature codesAll fields are optional and additive — existing applications ignoring them are unaffected.
Enrichment tooling
The pipeline script used to produce the enriched
cities.xmlis available athttps://github.com/comoglu/cities-xml-update — allowing operators to add their own cities or re-enrich from updated upstream data.