Skip to content

Commit

Permalink
minor bug correction
Browse files Browse the repository at this point in the history
  • Loading branch information
pszufe committed Jul 7, 2024
1 parent 47c06de commit 2dacafb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "OSMToolset"
uuid = "a1c25ae6-0f93-4b3a-bddf-c248cb99b9fa"
authors = ["pszufe <[email protected]> and contributors"]
version = "0.2.0"
version = "0.2.1"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand All @@ -11,7 +11,7 @@ NamedTupleTools = "d9ec5142-1e00-5aa0-9d6a-321866360f50"
OpenStreetMapX = "86cd37e6-c0ff-550b-95fe-21d72c8d4fc9"
Parsers = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
SpatialIndexing = "d4ead438-fe20-5cc5-a293-4fd39a41b74c"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[compat]
CSV = "0.10"
Expand All @@ -21,7 +21,7 @@ NamedTupleTools = "0.14"
OpenStreetMapX = "0.2, 0.3, 0.4"
Parsers = "2"
SpatialIndexing = "0.1.5, 0.1.6"
StatsBase = "0.28, 0.29, 0.30, 0.31, 0.32, 0.33, 0.34"
Statistics = "1.11"
julia = "1.6"

[extras]
Expand Down
3 changes: 1 addition & 2 deletions src/OSMToolset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ module OSMToolset
using CSV
using DataFrames
using SpatialIndexing
using StatsBase
using Statistics
using NamedTupleTools
using Parsers
using EzXML
import DataFrames: DataFrame
import OpenStreetMapX
import OpenStreetMapX: LLA, ENU, distance, MapData, center

Expand Down
29 changes: 14 additions & 15 deletions src/poi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,38 +141,35 @@ end
ScrapePOIConfig(df::DataFrame) = ScrapePOIConfig{AttractivenessMetaPOI}(df)


"""
Default built-in configuration for data scraping from OSM XML.
The default configuration will use AttractivenessMetaPOI
"""
const __builtin_config_path = joinpath(@__DIR__, "..", "config", "ScrapePOIconfig.csv")
ScrapePOIConfig() = ScrapePOIConfig{AttractivenessMetaPOI}(CSV.read(__builtin_config_path, DataFrame ))


function Base.show(io::IO, sp::ScrapePOIConfig{T}) where T <: AbstractMetaPOI
println(io, "ScrapePOIConfig{$T} with $(length(sp.meta)) keys:")
show(io, DataFrame(sp);summary=false,eltypes=false,allrows=true,rowlabel=:No)
end



"""
Default built-in configuration for data scraping from OSM XML.
The default configuration will use AttractivenessMetaPOI
"""
const __builtin_config_path = joinpath(@__DIR__, "..", "config", "ScrapePOIconfig.csv")
const __builtin_poiconfig = ScrapePOIConfig()


"""
find_poi(filename::AbstractString, scrape_config::ScrapePOIConfig{T <: AbstractMetaPOI}=__builtin_poiconfig; all_tags::Bool=false)
find_poi(filename::AbstractString, scrape_config::ScrapePOIConfig{T <: AbstractMetaPOI}=ScrapePOIConfig(); all_tags::Bool=false)
Generates a `DataFrame` with points of interests and from a given XML `filename`.
The data frame will also contain the metadata from `T` for each POI.
The `DataFrame` can be later used with `AttractivenessSpatIndex` to build an attractivenss spatial index.
The attractiveness values for the index will be used ones from the `scrape_config` file.
By default `__builtin_poiconfig` from `__builtin_config_path` will be used but you can define your own index.
By default `__builtin_config_path` will be used but you can define your own index.
Setting the `all_tags` parameter to `true` will cause that once the tag is matched, other tags within the same
`id` will be included in the resulting DataFrame.
"""
function find_poi(filename::AbstractString, scrape_config::ScrapePOIConfig{T}=__builtin_poiconfig; all_tags::Bool=false) where T <: AbstractMetaPOI
function find_poi(filename::AbstractString, scrape_config::ScrapePOIConfig{T}=ScrapePOIConfig(); all_tags::Bool=false) where T <: AbstractMetaPOI
dkeys = scrape_config.dkeys
dkeys_has_star = ("*" in dkeys)
meta = scrape_config.meta
Expand Down Expand Up @@ -288,7 +285,9 @@ function find_poi(filename::AbstractString, scrape_config::ScrapePOIConfig{T}=__
if !isnothing(a)
# we are interested only in attractive POIs
push!(df, (;elemtype,elemid,nodeid=curnode.id, lat=curnode.lat, lon=curnode.lon, key, value, ntfromstruct(a)...) )
all_tags_good_tag[] = true
all_tags_good_tag[] = all_tags
elseif all_tags
push!(all_tags_buffer, (key, value))
end
elseif all_tags
push!(all_tags_buffer, (key, string(get(attrs,"v",""))))
Expand Down Expand Up @@ -317,12 +316,12 @@ end

#=
"""
find_poi(osm::OpenStreetMapX.OSMData,scrape_config::ScrapePOIConfig=__builtin_poiconfig)
find_poi(osm::OpenStreetMapX.OSMData,scrape_config::ScrapePOIConfig=ScrapePOIConfig())
Finds POIs on the data from OSM parser. Please note that the OSM parser might not parse all the data from the XML file,
hence the results might be different than from `find_poi(filename::AbstractString)`.
Generally, usage of `find_poi(filename::AbstractString)` is stronlgy recommended.
"""
function find_poi(osm::OpenStreetMapX.OSMData,scrape_config::ScrapePOIConfig=__builtin_poiconfig)
function find_poi(osm::OpenStreetMapX.OSMData,scrape_config::ScrapePOIConfig=ScrapePOIConfig())
dkeys = scrape_config.dkeys
meta = scrape_config.meta
Expand Down

0 comments on commit 2dacafb

Please sign in to comment.