Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
pszufe committed Jul 28, 2023
1 parent db805aa commit d1dbec4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion config/Attractiveness.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class key points range values
class key influence range values
education amenity 3 2000 kindergarten
education amenity 5 3000 school,music_school,language_school
education amenity 20 10000 university,college
Expand Down
12 changes: 6 additions & 6 deletions src/attractiveness.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

struct AttractivenessData
class::Symbol
points::Int
range::Int
influence::Float64
range::Float64
enu::ENU
lla::LLA
end
Expand All @@ -26,7 +26,7 @@ The CSV file or DataFrame should have the following columns:
- class - data class in attractiveness index, each class name creates attractiveness dimension
- key - key in the XML file <tag>
- values - values in the <tag> (a star `"*"` catches all values)
- points - number of influance points
- influence - strength of influence
- range - maximum influence range in meters
When a `DataFrame` is provided the additional parameter `refLLA` can be provided for the reference
Expand All @@ -40,7 +40,7 @@ function AttractivenessSpatIndex(df::AbstractDataFrame, refLLA::LLA = LLA(mean(d
enu = ENU(lla, refLLA)
range_ = df.range[id]
rect = SpatialIndexing.Rect((enu.east-range_,enu.north-range_), (enu.east+range_,enu.north+range_))
a = AttractivenessData(Symbol(df.class[id]), df.points[id], df.range[id], enu, lla)
a = AttractivenessData(Symbol(df.class[id]), df.influence[id], df.range[id], enu, lla)
push!(data, SpatialElem(rect, id, a))
end
tree = RTree{Float64, 2}(Int, AttractivenessData, variant=SpatialIndexing.RTreeStar)
Expand Down Expand Up @@ -95,9 +95,9 @@ function attractiveness(sindex::AttractivenessSpatIndex, enu::ENU, aggregator::F
a = item.val # typeof(a) === AttractivenessData
poidistance = OpenStreetMapX.distance(enu, a.enu)
poidistance > a.range && continue
res[a.class] = aggregator(res[a.class], a.points * (a.range - poidistance) / a.range)
res[a.class] = aggregator(res[a.class], a.influence * (a.range - poidistance) / a.range)
if explain
append!(explanation, DataFrame(;a.class,a.points,poidistance,a.lla.lat,a.lla.lon))
append!(explanation, DataFrame(;a.class,a.influence,poidistance,a.lla.lat,a.lla.lon))
end
end
if explain
Expand Down
28 changes: 14 additions & 14 deletions src/poi.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

struct Attract
class::String
points::Int
influence::Int
range::Int
end
"""
Represents the configuration of the data scraping process from OSM XML.
Only those pieces of data will be scraped that are defined here.
The configuration is defined in a DataFrame with the following columns:
`class`, `key`, `values`, `points`, `range`.
`class`, `key`, `values`, `influence`, `range`.
Instead of the DataFrame a paths to a CSV file can be provided.
* Constructors *
Expand All @@ -28,17 +28,17 @@ end
const __builtin_attract_path = joinpath(@__DIR__, "..", "config", "Attractiveness.csv")

function AttractivenessConfig(df::DataFrame)
colnames = ["class", "key", "points", "range", "values"]
colnames = ["class", "key", "influence", "range", "values"]
@assert all(colnames .∈ Ref(names(df)))
dkeys = Set(df.key)
dkeys = Set(String.(df.key))
attract = Dict{Union{String, Tuple{String,String}}, Attract}()
for row in eachrow(df)
a = Attract(row.class, row.points, row.range)
for value in string.(split(row.values,','))
a = Attract(String(row.class), Float64(row.influence), Float64(row.range))
for value in string.(split(String(row.values),','))
if value == "*"
attract[row.key] = a
attract[String(row.key)] = a
else
attract[row.key, value] = a
attract[String(row.key), value] = a
end
end
end
Expand All @@ -47,7 +47,7 @@ end

function AttractivenessConfig(filename::AbstractString = __builtin_attract_path)
AttractivenessConfig(CSV.read(filename, DataFrame,types=Dict(
:class => String, :key => String, :points => Int, :range => Int, :values =>String) ))
:class => String, :key => String, :influence => Float64, :range => Float64, :values =>String) ))
end

const __builtin_attract = AttractivenessConfig()
Expand Down Expand Up @@ -156,12 +156,12 @@ function find_poi(filename::AbstractString; attract_config::AttractivenessConfig
a = get(attract, key, get(attract, (key, value), nothing))
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,a.class, a.points, a.range ) )
push!(df, (;elemtype,elemid,nodeid=curnode.id, lat=curnode.lat, lon=curnode.lon, key, value,a.class, a.influence, a.range ) )
end
end
end
end
df2 = DataFrame(g[findmax(g.points)[2], :] for g in groupby(df, [:nodeid, :class]))
df2 = DataFrame(g[findmax(g.influence)[2], :] for g in groupby(df, [:nodeid, :class]))
df2
end

Expand All @@ -176,11 +176,11 @@ function find_poi(osm::OSMData; attract_config::AttractivenessConfig=__builtin_a
# otherwise try to get attractiveness for the tuple
a = get(attract, key, get(attract, (key, value), nothing))
if a !== nothing
# we are interested only in attractive POIs #push!(df, (;elemtype, elemid, nodeid=curnode.id, lat=curnode.lat, lon=curnode.lon, key, value, a.class, a.points, a.range))
# we are interested only in attractive POIs
lla = osm.nodes[node]
push!(df, (;nodeid=node, lat=lla.lat, lon=lla.lon, key, value, a.class, a.points, a.range))
push!(df, (;nodeid=node, lat=lla.lat, lon=lla.lon, key, value, a.class, a.influence, a.range))
end
end
df2 = DataFrame(g[findmax(g.points)[2], :] for g in groupby(df, [:nodeid, :class]))
df2 = DataFrame(g[findmax(g.influence)[2], :] for g in groupby(df, [:nodeid, :class]))
return df2
end
2 changes: 1 addition & 1 deletion test/data/Attractiveness.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class key points range values
class key influence range values
education amenity 3 2000 kindergarten
education amenity 5 3000 school,music_school,language_school
education amenity 20 10000 university,college
Expand Down

0 comments on commit d1dbec4

Please sign in to comment.