Skip to content

Commit

Permalink
Updating the shapefile in data.jl, and accordingly making the changes…
Browse files Browse the repository at this point in the history
… to the Karmana.jl and indiaoutline.jl
  • Loading branch information
siddjain444 committed Apr 11, 2024
1 parent 4e3b2d1 commit 6214951
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 30 deletions.
26 changes: 11 additions & 15 deletions src/Karmana.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function __init__()
district_df[][302, :HR_Nmbr] = 3 # Kinnaur - district name not assigned HR_Name
district_df[][413, :HR_Nmbr] = 3 # North Sikkim - district not assigned HR_Name nor district name # 104
end
hr_df[] = _prepare_merged_geom_dataframe(district_df[], :HR_Nmbr, :ST_NM; capture_fields = (:ST_NM, :ST_CD, :HR_Name))
hr_df[] = _prepare_merged_geom_dataframe(district_df[], :HR_Nmbr, :ST_NM; capture_fields = (:ST_NM, :ST_CD, :HR_Nmbr))
state_df[] = _prepare_merged_geom_dataframe(district_df[], :ST_NM; capture_fields = (:ST_CD,))

# finally, patch the loaded dataframes, to match the maps database
Expand All @@ -147,20 +147,16 @@ function __init__()
has_india_data = true

elseif has_maps_db_config
try
_state_df, _hr_df, _district_df = state_hr_district_dfs()

# _district_df[302, :hr_nmbr] = 3 # Kinnaur - district name not assigned HR_Name
# _district_df[413, :hr_nmbr] = 3 # North Sikkim - district not assigned HR_Name nor district name
state_df[] = _state_df
hr_df[] = _hr_df
district_df[] = _district_df
has_india_data = true
catch e
@warn "Failed to load data from maps database. Falling back to shapefile."
@warn e
has_india_data = false
end
# try
_district_df = state_hr_district_dfs()
district_df[] = _district_df
district_df[].geometry = GeoInterface.convert.((GeometryBasics,), district_df[].geometry)
# apply certain patches here, if needed
district_df[][302, :hr_nmbr] = 3 # Kinnaur - district name not assigned HR_Name
district_df[][413, :hr_nmbr] = 3 # North Sikkim - district not assigned HR_Name nor district name # 104
hr_df[] = _prepare_merged_geom_dataframe(district_df[], :hr_nmbr, :st_nm; capture_fields = (:st_nm, :st_cd, :hr_name))
state_df[] = _prepare_merged_geom_dataframe(district_df[], :st_nm; capture_fields = (:st_cd,))
hr_df[].hr_nmbr_str = ("HR ",) .* string.(hr_df[].hr_nmbr)
end

if !has_india_data # no shapefile path, no maps db access ⟹ use the artifact!
Expand Down
10 changes: 2 additions & 8 deletions src/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,15 @@ function state_hr_district_dfs()
spatial_ref_df = DBInterface.execute(connection, "SELECT * from spatial_ref_sys") |> DataFrame
db_crs = spatial_ref_df.SRTEXT[begin] # TODO: use this when converting.
# get tables for each admin level
state_table = do_geoquery(connection, "states")
hr_table = do_geoquery(connection, "homogeneous_regions")
district_table = do_geoquery(connection, "districts_2011")
district_table = do_geoquery(connection,"districts_states_hr" )
# get rivers etc
shape_wkb_to_module_geom!(GeometryBasics, state_table)
shape_wkb_to_module_geom!(GeometryBasics, hr_table)
shape_wkb_to_module_geom!(GeometryBasics, district_table)
# drop missing values, since we shouldn't have any at this stage.
dropmissing!(state_table)
dropmissing!(hr_table)
dropmissing!(district_table)
# clean up by closing the connection
DBInterface.close!(connection)

return state_table, hr_table, district_table
return district_table

end

Expand Down
12 changes: 5 additions & 7 deletions src/plotting/indiaoutline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function id_key_for_admin_level(admin_level::Symbol)
elseif admin_level == :HR
:hr_nmbr
elseif admin_level == :District
:dt_cen_cd
:censuscode
else
@error("The admin code `$admin_code` which you passed is invalid. Valid admin codes are `:State`, `:HR`, and `:District`.")
end
Expand Down Expand Up @@ -261,16 +261,14 @@ function Makie.plot!(plot::IndiaOutline)
end
notify(plot.converted[2])

state_plot = poly!(plot, plot.State, state_geoms; color = state_colors, colormap = plot.colormap, highclip = plot.highclip, lowclip = plot.lowclip)
hr_plot = poly!(plot, hr_geoms; color = hr_colors, colorrange = get(plot, :colorrange, (0, 1)), colormap = plot.colormap, highclip = plot.highclip, lowclip = plot.lowclip, plot.HR...)
district_plot = poly!(plot, district_geoms; color = district_colors, colormap = plot.colormap, colorrange = get(plot, :colorrange, (0, 1)), highclip = plot.highclip, lowclip = plot.lowclip, plot.District...)
river_plot = lines!(plot, GeoInterface.convert(GeometryBasics, Karmana.india_rivers[]); inspectable = false, xautolimits = false, yautolimits = false, plot.River...)

state_plot = poly!(plot, plot.State, state_geoms; color = state_colors, colormap = plot.colormap)
hr_plot = poly!(plot, hr_geoms; color = hr_colors, colorrange = get(plot, :colorrange, (0, 1)), colormap = plot.colormap, plot.HR...)
district_plot = poly!(plot, district_geoms; color = district_colors, colormap = plot.colormap, colorrange = get(plot, :colorrange, (0, 1)), plot.District...)


on(Base.Fix1(_set_plot_z, state_plot), plot.State.zlevel; update = true)
on(Base.Fix1(_set_plot_z, hr_plot), plot.HR.zlevel; update = true)
on(Base.Fix1(_set_plot_z, district_plot), plot.District.zlevel; update = true)
on(Base.Fix1(_set_plot_z, river_plot), plot.River.zlevel; update = true)

return plot
end
Expand Down

0 comments on commit 6214951

Please sign in to comment.