---
title: "How to generate a sampling design from a boundary of interest in kml file?"
url: "https://openforis.support/questions/845/how-to-generate-a-sampling-design-from-a-boundary-of-interest-in-kml-file"
tags: ["collect"]
status: "answered"
score: 0
answer_count: 3
asked: "2016-11-01T13:43:56"
last_activity: "2019-03-30T22:57:52"
source: "Open Foris Support - Q&A Forum"
license: "Copyright Open Foris, 2026. Some rights reserved under creative commons license."
---

# How to generate a sampling design from a boundary of interest in kml file?

Asked by kanchana on 2016-11-01

Dear Collect Team

I have a kml file with an area of interest. While I am aware that Collect provides option for plot layout, I would like to generate a sampling design for the kml file. It would be great if you could help me guide on the steps to generate the sampling (I am looking for a systematic sampling, with plots at regular intervals) which also allows me to change the sampling density.

Thanks much!


## Answer (score 0, by anish on 2016-11-01)

Link: https://openforis.support/questions/845/how-to-generate-a-sampling-design-from-a-boundary-of-interest-in-kml-file/846

Hi

You could use Quantum GIS (QGIS) to generate systematic sampling grids at regular intervals. Use Vector > Research Tools > Regular Points tool to create regular grids within the KML area of interest. You can either create grids at regular geographic units (deg/min/sec) or Cartesian distance in meters. For changing the sampling density, use the grid spacing option. Once you create the systematic grids, you could export this data as KML and then import using Collect or Collect Earth. 

Hope this helps

Anish


## Answer (score 0, by collectearth on 2016-11-02)

Link: https://openforis.support/questions/845/how-to-generate-a-sampling-design-from-a-boundary-of-interest-in-kml-file/851

Hello Kanchana,

Another option, if you prefer to use Google Earth Engine is to use one of the scripts that we have been using to generate grids. This script has the advantage of being quite fast and easy to adapt to other areas.

The first thing you need to do is to upload the KML file with your boundaries to a Fusion Table. You can follow [these instructions][1] to upload the KML. You then need to copy the ID of the table so that you can use it in your script!

The selected part of the URL is the ID of the table.
![alt text][2]

For instance, I have upload the KML file with boundaries for Spain (obtained from the [Global Administrative Areas][3] project ) and this is the result : [LINK TO FUSION TABLE PROVINCES OF SPAIN][4]. Make sure that the column types are set to "Text", as Fusion Tables sometimes understands column with names of cities, provinces or areas as Location columns and then you are not able to filter using those columns.

Now, you need to click on [this link GEE SCRIPT][5] and adapt it to your needs. Mainly you will need to change:

 - Line 5 : set the **fusion table ID**
   using the one that you just uploaded!
 - Line 8 : **Filter the fusion table**
   using the column and value that is
   relevant to your table 
 - Line 29 : Set
   the **distance in meters** between plots!
   By default is set to 1000 meters 
 - Line
   34 : Set the **EPSG code** for the
   projection of the area that you will
   be working on

Once this is fixed you can click on the **Run button** and a link will appear on the right frame. If you click [on that link][6] (starts like https://earthengine.googleapis.com/... ) then a CSV file will be downloaded to your computer.

This will contain data like this: 

    system:index,latitude,longitude,elevation,slope,aspect,climate,soil,gez
    0,37.94540395139881,-6.183373895436064,435,1,171,2,6,22.0
    1,37.95440601040461,-6.183029911173734,461,1,184,2,6,22.0
    2,37.95413303300725,-6.171660954018713,447,1,163,2,6,22.0
    3,37.96475691863039,-6.239539769372606,501,0,301,2,6,22.0
    4,37.96448934041179,-6.2281686672070125,477,1,148,2,6,22.0


You can open this in Excel or Libre Office and adpat the columns. By default, the Collect Earth template contains the elevation, slope and aspect attributes. CLimate, Soil and Global Ecologic Zone are attributes ("From CSV") that are used in other surveys such as the Global Pilot Assessment survey.

Let me know if this clarifies your question or just made it sound more complex!


  [1]: https://developers.google.com/earth-engine/importing
  [2]: http://www.openforis.org/support/upfiles/chrome_2016-11-02_12-56-32.png
  [3]: http://www.gadm.org
  [4]: https://www.google.com/fusiontables/DataSource?docid=1Oz-84t5pEQgP1I_EQPYmQ-BoqnvumpS_eo0-2YgV
  [5]: https://code.earthengine.google.com/0897653f3a89492eb8dad0fb28f707a0
  [6]: https://code.earthengine.google.com/0897653f3a89492eb8dad0fb28f707a0


## Answer (score 0, by collectearth on 2019-03-30)

Link: https://openforis.support/questions/845/how-to-generate-a-sampling-design-from-a-boundary-of-interest-in-kml-file/2230

Here is an updated version of the grid generation script from Google Earth Engine

[https://collectearth.users.earthengine.app/view/collect-earth-grid-generator][1]


  [1]: https://collectearth.users.earthengine.app/view/collect-earth-grid-generator
