Skip to content
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

Open
lambdatronic opened this issue Dec 21, 2016 · 1 comment
Open

Allow uploading a shapefile containing all plot centers #34

lambdatronic opened this issue Dec 21, 2016 · 1 comment

Comments

@lambdatronic
Copy link
Member

Automatically calculate their minimum bounding box and use this as the project's lat/lon min/max values.

@lambdatronic
Copy link
Member Author

Here is an example from Peter Cutter's Thailand workshop project:

  1. Project Title: FAO Regional Subset Collection
  2. Size of plots: r=39.493 meters (please check my math--the FAO square
    plot is 70 x 70 meters = 4900 m^2...and we want the big circles to be the
    same area)
  3. Number of sub-plots (small circles) = 49
  4. Class choices:
    • Tree
    • Shrub
    • Palm
    • Bamboo
    • Crop
    • Infrastructure
    • Water

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant