added osm analyze

This commit is contained in:
j.mei7
2022-03-26 22:51:25 +01:00
parent 791000d47b
commit d2a56576c2
9 changed files with 456 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
<div *ngIf="osmAnalysis">
{{ osmAnalysis.publicTransportAccessability.isBusAccessible }}
</div>

View File

@@ -1,5 +1,10 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router'
import { OverpassApiService } from '../services/overpass-api.service';
import { OsmAnalysis } from '../interfaces/osmAnalysis';
import { OsmService } from '../services/osm.service';
import { OSM } from '../interfaces/osm';
import { OsmAnalysisService } from '../services/osm-analysis.service';
@Component({
selector: 'app-analyze',
@@ -9,13 +14,32 @@ import { ActivatedRoute } from '@angular/router'
export class AnalyzeComponent implements OnInit {
lon!: string | null;
lat!: string | null;
osmAnalysis?: OsmAnalysis;
constructor(
private route: ActivatedRoute,
private overpassApiService: OverpassApiService,
private osmService: OsmService,
private osmAnalysisService: OsmAnalysisService
) { }
ngOnInit() {
this.lon = this.route.snapshot.paramMap.get('lon');
this.lat = this.route.snapshot.paramMap.get('lat');
let minLon: number = parseFloat(this.lon!) - 0.1;
let maxLon: number = parseFloat(this.lon!) + 0.1;
let minLat: number = parseFloat(this.lat!) - 0.13;
let maxLat: number = parseFloat(this.lat!) + 0.13;
this.overpassApiService.sendQueryRequest(`${minLon},${minLat},${maxLon},${maxLat}`).subscribe(data => {
console.log(data);
let osm: OSM = this.osmService.parseOsmContent(data);
// Analyze the OSM data
this.osmAnalysis = this.osmAnalysisService.getOsmAnalysis(osm);
});
}
}

93
src/app/interfaces/osm.ts Normal file
View File

@@ -0,0 +1,93 @@
export interface OSMContact{
phone?: string;
fax?: string;
email?: string;
website?: string;
mobile?: string;
vk?: string;
facebook?: string;
instagram?: string;
twitter?: string;
youtube?: string;
ok?: string;
webcam?: string;
telegram?: string;
whatsapp?: string;
linkedin?: string;
pinterest?: string;
viper?: string;
foursquare?: string;
skype?: string;
xing?: string;
vhf?: string;
flickr?: string;
mastodon?: string;
sip?: string;
diaspora?: string;
gnusocial?: string;
}
export interface OSMAddress{
housenumber?: string;
street?: string;
place?: string;
city?: string;
postcode?: string;
country?: string;
suburb?: string;
state?: string;
province?: string;
}
export interface OSMPlace{
nodeIds?: Array<string>;
type?: string;
name?: string;
address?: OSMAddress;
contact?: OSMContact;
openingHours?: string;
}
export interface OSMNode{
id?: string;
lon?: string;
lat?: string;
version?: string;
timestamp?: string;
changeset?: string;
uid?: string;
user?: string;
}
export interface OSMNodeTag{
id?: string;
nodeId?: string;
key?: string;
value?: string;
}
export interface OSMWay{
id?: string;
version?: string;
timestamp?: string;
changeset?: string;
uid?: string;
user?: string;
}
export interface OSMWayTag{
id?: string;
wayId?: string;
key?: string;
value?: string;
}
export interface OSM{
nodes?: Array<OSMNode>;
nodeTags?: Array<OSMNodeTag>;
ways?: Array<OSMWay>;
wayTags?: Array<OSMWayTag>;
places?: Array<OSMPlace>;
}

View File

@@ -0,0 +1,14 @@
export interface PublicTransportAccessability {
isBusAccessible: boolean;
isTramAccessible: boolean;
isTrainAccessible: boolean;
isLightRailAccessible: boolean;
isMonorailAccessible: boolean;
isSubwayAccessible: boolean;
}
export interface OsmAnalysis {
publicTransportAccessability: PublicTransportAccessability;
}

View File

@@ -0,0 +1,16 @@
/* tslint:disable:no-unused-variable */
import { TestBed, async, inject } from '@angular/core/testing';
import { OsmAnalysisService } from './osm-analysis.service';
describe('Service: OsmAnalysis', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [OsmAnalysisService]
});
});
it('should ...', inject([OsmAnalysisService], (service: OsmAnalysisService) => {
expect(service).toBeTruthy();
}));
});

View File

@@ -0,0 +1,47 @@
import { Injectable } from '@angular/core';
import { OSM } from '../interfaces/osm';
import { OsmAnalysis, PublicTransportAccessability } from '../interfaces/osmAnalysis';
@Injectable({
providedIn: 'root'
})
export class OsmAnalysisService {
constructor() { }
getPublicTransportAccessability(osm: OSM): PublicTransportAccessability {
let publicTransportAccessability: PublicTransportAccessability = {
isBusAccessible: false,
isTramAccessible: false,
isTrainAccessible: false,
isLightRailAccessible: false,
isMonorailAccessible: false,
isSubwayAccessible: false
};
for(let nodeTag of osm.nodeTags!){
if(nodeTag.key === "highway" && nodeTag.value === "bus_stop"){
publicTransportAccessability.isBusAccessible = true;
}else if(nodeTag.key === "railway" && nodeTag.value === "tram_stop"){
publicTransportAccessability.isTramAccessible = true;
}else if(nodeTag.key === "railway" && nodeTag.value === "station"){
publicTransportAccessability.isTrainAccessible = true;
}else if(nodeTag.key === "station" && nodeTag.value === "light_rail"){
publicTransportAccessability.isLightRailAccessible = true;
}else if(nodeTag.key === "station" && nodeTag.value === "monorail"){
publicTransportAccessability.isMonorailAccessible = true;
}else if(nodeTag.key === "station" && nodeTag.value === "subway"){
publicTransportAccessability.isSubwayAccessible = true;
}
}
return publicTransportAccessability;
}
getOsmAnalysis(osm: OSM): OsmAnalysis {
let osmAnalysis: OsmAnalysis = {
publicTransportAccessability: this.getPublicTransportAccessability(osm)
};
return osmAnalysis;
}
}

View File

@@ -1,10 +1,236 @@
import { Injectable } from '@angular/core';
import { OsmAnalysis } from '../interfaces/osmAnalysis';
import { OSMNode, OSMNodeTag, OSMWay, OSMWayTag, OSMPlace, OSMContact, OSMAddress, OSM } from '../interfaces/osm';
@Injectable({
providedIn: 'root'
})
export class OsmService {
nodeList: OSMNode[] = [];
nodeTagList: OSMNodeTag[] = [];
wayList: OSMWay[] = [];
wayTagList: OSMWayTag[] = [];
placeList: OSMPlace[] = [];
constructor() { }
parseOsmContent(osmData: string): OSM{
this.nodeList = [];
this.nodeTagList = [];
this.wayList = [];
this.wayTagList = [];
this.placeList = [];
let lines = osmData.split('\n');
let nodeLines: string[] = [];
let wayLines: string[] = [];
for(let line of lines){
if(line.includes("<node")){
if(line.includes("/>")){
this.createNode([line]);
nodeLines = [];
}else{
nodeLines.push(line);
}
}else if(line.includes("</node>")){
this.createNode(nodeLines);
nodeLines = [];
}else if(nodeLines.length > 0){
nodeLines.push(line);
}else if(line.includes("<way")){
wayLines.push(line);
}else if(line.includes("</way>")){
this.createWay(wayLines);
wayLines = [];
}else if(wayLines.length > 0){
wayLines.push(line);
}
}
let osm: OSM = {
nodes: this.nodeList,
nodeTags: this.nodeTagList,
ways: this.wayList,
wayTags: this.wayTagList,
places: this.placeList
};
return osm;
}
createContact(lines: string[]): OSMContact{
let contact: OSMContact = {};
for(let line of lines){
if(line.includes("<tag ")){
let key = line.split('k="')[1].split('"')[0];
let value = line.split('v="')[1].split('"')[0];
if(key == "contact:phone"){
contact.phone = value;
}else if(key == "contact:website"){
contact.website = value;
}else if(key == "contact:email"){
contact.email = value;
}else if(key == "contact:fax"){
contact.fax = value;
}else if(key == "contact:facebook"){
contact.facebook = value;
}else if(key == "contact:twitter"){
contact.twitter = value;
}else if(key == "contact:instagram"){
contact.instagram = value;
}else if(key == "contact:youtube"){
contact.youtube = value;
}else if(key == "contact:ok"){
contact.ok = value;
}else if(key == "contact:vk"){
contact.vk = value;
}else if(key == "contact:whatsapp"){
contact.whatsapp = value;
}else if(key == "contact:telegram"){
contact.telegram = value;
}else if(key == "contact:skype"){
contact.skype = value;
}else if(key == "contact:linkedin"){
contact.linkedin = value;
}else if(key == "contact:sip"){
contact.sip = value;
}else if(key == "contact:diaspora"){
contact.diaspora = value;
}else if(key == "contact:gnusocial"){
contact.gnusocial = value;
}else if(key == "contact:xing"){
contact.xing = value;
}else if(key == "contact:flickr"){
contact.flickr = value;
}else if(key == "contact:foursquare"){
contact.foursquare = value;
}
}
}
return contact;
}
createAddress(lines: string[]): OSMAddress{
let address: OSMAddress = {};
for(let line of lines){
if(line.includes("<tag ")){
let key = line.split('k="')[1].split('"')[0];
let value = line.split('v="')[1].split('"')[0];
if(key == "addr:street"){
address.street = value;
}else if(key == "addr:housenumber"){
address.housenumber = value;
}else if(key == "addr:postcode"){
address.postcode = value;
}else if(key == "addr:city"){
address.city = value;
}else if(key == "addr:country"){
address.country = value;
}else if(key == "addr:state"){
address.state = value;
}else if(key == "addr:province"){
address.province = value;
}else if(key == "addr:suburb"){
address.suburb = value;
}else if(key == "addr:place"){
address.place = value;
}
}
}
return address;
}
createPlace(lines: string[], isShop: boolean): void{
let place: OSMPlace = {};
place.nodeIds = [];
place.address = this.createAddress(lines);
place.contact = this.createContact(lines);
for(let line of lines){
if(line.includes("<tag ")){
let key = line.split('k="')[1].split('"')[0];
let value = line.split('v="')[1].split('"')[0];
if(key == "amenity" && !isShop){
place.type = value;
}else if(key == "shop" && isShop){
place.type = value;
}else if(key == "name"){
place.name = value;
}else if(key == "opening_hours"){
place.openingHours = value;
}
}else if(line.includes("<nd ")){
place.nodeIds!.push(line.split('ref="')[1].split('"')[0]);
}else if(line.includes("<node")){
place.nodeIds!.push(line.split('id="')[1].split('"')[0]);
}
}
this.placeList.push(place);
}
createWay(lines: string[]): void{
let way: OSMWay = {};
for(let line of lines){
if(line.includes("<way ")){
way.id = line.split('id="')[1].split('"')[0];
way.version = line.split('version="')[1].split('"')[0];
way.changeset = line.split('changeset="')[1].split('"')[0];
way.timestamp = line.split('timestamp="')[1].split('"')[0];
way.user = line.split('user="')[1].split('"')[0];
way.uid = line.split('uid="')[1].split('"')[0];
}else if(line.includes("<tag ")){
let key = line.split('k="')[1].split('"')[0];
let value = line.split('v="')[1].split('"')[0];
let wayTag: OSMWayTag = {
key: key,
value: value
};
this.wayTagList.push(wayTag);
if(key == "shop"){
this.createPlace(lines, true);
}else if(key == "amenity"){
this.createPlace(lines, false);
}
}
}
this.wayList.push(way);
}
createNode(lines: string[]): void{
let node: OSMNode = {};
for(let line of lines){
if(line.includes("<node ")){
node.id = line.split('id="')[1].split('"')[0];
node.version = line.split('version="')[1].split('"')[0];
node.changeset = line.split('changeset="')[1].split('"')[0];
node.timestamp = line.split('timestamp="')[1].split('"')[0];
node.user = line.split('user="')[1].split('"')[0];
node.uid = line.split('uid="')[1].split('"')[0];
}else if(line.includes("<tag ")){
let key = line.split('k="')[1].split('"')[0];
let value = line.split('v="')[1].split('"')[0];
let nodeTag: OSMNodeTag = {
key: key,
value: value
};
this.nodeTagList.push(nodeTag);
}
}
this.nodeList.push(node);
}
}

View File

@@ -0,0 +1,16 @@
/* tslint:disable:no-unused-variable */
import { TestBed, async, inject } from '@angular/core/testing';
import { OverpassApiService } from './overpass-api.service';
describe('Service: OverpassApi', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [OverpassApiService]
});
});
it('should ...', inject([OverpassApiService], (service: OverpassApiService) => {
expect(service).toBeTruthy();
}));
});

View File

@@ -0,0 +1,16 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class OverpassApiService {
constructor(private http: HttpClient) { }
sendQueryRequest(queryString: string){
console.log("queryString: " + queryString);
return this.http.get("https://overpass-api.de/api/map?bbox=" + queryString, { observe: 'body', responseType: 'text'});
}
}