-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow uploading a shapefile containing all plot centers #34
Comments
Here is an example from Peter Cutter's Thailand workshop project:
To create this project, I ran the following code from within a Boot REPL: (require 'mapcha.db)
(in-ns 'mapcha.db)
(def fao-grid-points (csv/read-csv (io/reader "fao_grid_points.csv")))
(def fao-lat-lon (map (juxt #(Double/parseDouble (second %))
#(Double/parseDouble (nth % 2)))
(rest fao-grid-points)))
(def boundary-lon-min (reduce min (map second fao-lat-lon)))
(def boundary-lon-max (reduce max (map second fao-lat-lon)))
(def boundary-lat-min (reduce min (map first fao-lat-lon)))
(def boundary-lat-max (reduce max (map first fao-lat-lon)))
(def project-id
(:id (first (add-project-sql {:name "FAO Regional Subset Collection v2"
:description ""
:lon_min boundary-lon-min
:lon_max boundary-lon-max
:lat_min boundary-lat-min
:lat_max boundary-lat-max}))))
(doseq [[plot-lat plot-lon] fao-lat-lon]
(let [plot-info (first
(add-plot-sql {:project_id project-id
:lon plot-lon
:lat plot-lat
:radius 39.493}))
plot-id (plot-info :id)
plot-x (plot-info :web_mercator_x)
plot-y (plot-info :web_mercator_y)]
(dotimes [_ 49]
(let [offset-angle (rand (* 2.0 Math/PI))
offset-magnitude (rand 39.493)
x-offset (* offset-magnitude (Math/cos offset-angle))
y-offset (* offset-magnitude (Math/sin offset-angle))]
(add-sample-sql {:plot_id plot-id
:sample_x (+ plot-x x-offset)
:sample_y (+ plot-y y-offset)})))))
(add-sample-value-sql {:project_id project-id :value "Tree" :color "#12660E" :image nil})
(add-sample-value-sql {:project_id project-id :value "Shrub" :color "#89D815" :image nil})
(add-sample-value-sql {:project_id project-id :value "Palm" :color "#D8C315" :image nil})
(add-sample-value-sql {:project_id project-id :value "Bamboo" :color "#D86315" :image nil})
(add-sample-value-sql {:project_id project-id :value "Crop" :color "#D81515" :image nil})
(add-sample-value-sql {:project_id project-id :value "Infrastructure" :color "#D815B4" :image nil})
(add-sample-value-sql {:project_id project-id :value "Water" :color "#154CD8" :image nil}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Automatically calculate their minimum bounding box and use this as the project's lat/lon min/max values.
The text was updated successfully, but these errors were encountered: