Item methods to work out if it is a linear feature

This commit is contained in:
Edward Betts 2021-10-22 09:54:04 +01:00
parent 38e23ec8cc
commit 9c426b2918

View file

@ -159,16 +159,40 @@ class Item(Base):
return isa_list return isa_list
def get_isa_qids(self): def get_isa_qids(self):
return [v["id"] for v in self.get_claim("P31") if v] return [isa["id"] for isa in self.get_isa()]
def is_street(self): def is_street(self, isa_qids=None):
street_items = { if isa_qids is None:
'Q34442', # road isa_qids = self.get_isa_qids()
'Q79007', # street
'Q83620', # thoroughfare matching_types = {
'Q21000333', # shopping street "Q12731", # dead end street
"Q34442", # road
"Q79007", # street
"Q83620", # thoroughfare
"Q21000333", # shopping street
"Q62685721", # pedestrian street
} }
return bool(street_items & set(self.get_isa_qids())) return bool(matching_types & set(isa_qids))
def is_watercourse(self, isa_qids=None):
if isa_qids is None:
isa_qids = self.get_isa_qids()
matching_types = {
"Q355304", # watercourse
"Q4022", # river
"Q47521", # stream
"Q1437299", # creek
"Q63565252", # brook
"Q12284", # canal
"Q55659167", # natural watercourse
}
return bool(matching_types & set(isa_qids))
def is_linear_feature(self):
isa_qids = set(self.get_isa_qids())
return self.is_street(isa_qids) or self.is_watercourse(isa_qids)
def is_tram_stop(self): def is_tram_stop(self):
return 'Q2175765' in self.get_isa_qids() return 'Q2175765' in self.get_isa_qids()