Calculating intersect for two featurecollectionsCalculating cost distance in Google Earth Engine?Charting two FeatureCollections in Google Earth Engine?Why I cannot use mean() after merging two imageColletions?Q: Google Earth Engine: Calculating deforestation for individual areas (Hansen/Global Forest Change dataset)Google Earth Engine, how to distinguish between rivers/streams and ponds/lakes in a water maskFiltering Images that Intersect with FeaturesMerge FeatureCollections excluding overlap in Google Earth EngineGoogle Earth Engine code for calculating NDWI from sentinel 2 image collection?Calculating percentage of pixels in polygon with specific value using Google Earth Engine?Spatial join between two FeatureCollections in Earth Engine
Why does Arabsat 6A need a Falcon Heavy to launch
Why doesn't H₄O²⁺ exist?
SSH "lag" in LAN on some machines, mixed distros
What is the most common color to indicate the input-field is disabled?
How to model explosives?
Facing a paradox: Earnshaw's theorem in one dimension
What is the intuition behind short exact sequences of groups; in particular, what is the intuition behind group extensions?
How to draw the figure with four pentagons?
Is it possible to run Internet Explorer on OS X El Capitan?
How could indestructible materials be used in power generation?
Is it unprofessional to ask if a job posting on GlassDoor is real?
Took a trip to a parallel universe, need help deciphering
Doing something right before you need it - expression for this?
Forgetting the musical notes while performing in concert
Could gravitational lensing be used to protect a spaceship from a laser?
I Accidentally Deleted a Stock Terminal Theme
What is going on with Captain Marvel's blood colour?
AES: Why is it a good practice to use only the first 16bytes of a hash for encryption?
What mechanic is there to disable a threat instead of killing it?
How much of data wrangling is a data scientist's job?
How do I write bicross product symbols in latex?
What to put in ESTA if staying in US for a few days before going on to Canada
What's the point of deactivating Num Lock on login screens?
Is it legal for company to use my work email to pretend I still work there?
Calculating intersect for two featurecollections
Calculating cost distance in Google Earth Engine?Charting two FeatureCollections in Google Earth Engine?Why I cannot use mean() after merging two imageColletions?Q: Google Earth Engine: Calculating deforestation for individual areas (Hansen/Global Forest Change dataset)Google Earth Engine, how to distinguish between rivers/streams and ponds/lakes in a water maskFiltering Images that Intersect with FeaturesMerge FeatureCollections excluding overlap in Google Earth EngineGoogle Earth Engine code for calculating NDWI from sentinel 2 image collection?Calculating percentage of pixels in polygon with specific value using Google Earth Engine?Spatial join between two FeatureCollections in Earth Engine
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am trying to calculate the area of watershed within each polygon for a set of square polygons (1km*1km) in my study area. I converted a water image to a featureCollection of water polygons, it works great. I get an error when I try to intersect the square polygon layer to the water featureCollection. I also would like to export the result to a csv.
//my study area
var studyArea = ee.FeatureCollection('users/oamram/ABM_Kenya/StudyArea');
//square polygons 1km in dimensions
var polygons = ee.FeatureCollection('users/oamram/ABM_Kenya/Polygons1km');
Map.centerObject(studyArea,13);
var start = '2014-01-01';
var finish = '2014-01-31';
//get water dataset
var dataset = ee.ImageCollection('JRC/GSW1_0/MonthlyHistory')
.filter(ee.Filter.date(start, finish));
//select water layer
var water = dataset.select('water');
//identify water area
var sumWater = water.reduce(ee.Reducer.sum());
//clip to my study area
var clipped = sumWater.clip(studyArea);
var waterVis =
min: 0.0,
max: 2.0,
palette: ['ffffff', 'fffcb8', '0905ff'],
;
//Apply watermask- water values =2 in this layer//;
var maskedComposite = clipped.updateMask(clipped.eq(2));
// Convert the water areas to vectors.
var vectors = maskedComposite.reduceToVectors(
geometry: studyArea,
crs: maskedComposite.projection(),
scale: 30,
geometryType: 'polygon',
eightConnected: false,
labelProperty: 'water'
);
**//everything works up to here**
// Compute the intersection, for each feature in the feature collection.
var polyIntersect = polygons.map(function(feature)
var intersection = vectors.intersection(feature, ee.ErrorMargin(1));
return feature.set('Intersect': intersection.area().divide(1000 * 1000));
);
The error is get is this:
vectors.intersection is not a function
google-earth-engine
New contributor
add a comment |
I am trying to calculate the area of watershed within each polygon for a set of square polygons (1km*1km) in my study area. I converted a water image to a featureCollection of water polygons, it works great. I get an error when I try to intersect the square polygon layer to the water featureCollection. I also would like to export the result to a csv.
//my study area
var studyArea = ee.FeatureCollection('users/oamram/ABM_Kenya/StudyArea');
//square polygons 1km in dimensions
var polygons = ee.FeatureCollection('users/oamram/ABM_Kenya/Polygons1km');
Map.centerObject(studyArea,13);
var start = '2014-01-01';
var finish = '2014-01-31';
//get water dataset
var dataset = ee.ImageCollection('JRC/GSW1_0/MonthlyHistory')
.filter(ee.Filter.date(start, finish));
//select water layer
var water = dataset.select('water');
//identify water area
var sumWater = water.reduce(ee.Reducer.sum());
//clip to my study area
var clipped = sumWater.clip(studyArea);
var waterVis =
min: 0.0,
max: 2.0,
palette: ['ffffff', 'fffcb8', '0905ff'],
;
//Apply watermask- water values =2 in this layer//;
var maskedComposite = clipped.updateMask(clipped.eq(2));
// Convert the water areas to vectors.
var vectors = maskedComposite.reduceToVectors(
geometry: studyArea,
crs: maskedComposite.projection(),
scale: 30,
geometryType: 'polygon',
eightConnected: false,
labelProperty: 'water'
);
**//everything works up to here**
// Compute the intersection, for each feature in the feature collection.
var polyIntersect = polygons.map(function(feature)
var intersection = vectors.intersection(feature, ee.ErrorMargin(1));
return feature.set('Intersect': intersection.area().divide(1000 * 1000));
);
The error is get is this:
vectors.intersection is not a function
google-earth-engine
New contributor
The error can't be reproduced because the features are not publicly available.
– JepsonNomad
Apr 2 at 0:29
add a comment |
I am trying to calculate the area of watershed within each polygon for a set of square polygons (1km*1km) in my study area. I converted a water image to a featureCollection of water polygons, it works great. I get an error when I try to intersect the square polygon layer to the water featureCollection. I also would like to export the result to a csv.
//my study area
var studyArea = ee.FeatureCollection('users/oamram/ABM_Kenya/StudyArea');
//square polygons 1km in dimensions
var polygons = ee.FeatureCollection('users/oamram/ABM_Kenya/Polygons1km');
Map.centerObject(studyArea,13);
var start = '2014-01-01';
var finish = '2014-01-31';
//get water dataset
var dataset = ee.ImageCollection('JRC/GSW1_0/MonthlyHistory')
.filter(ee.Filter.date(start, finish));
//select water layer
var water = dataset.select('water');
//identify water area
var sumWater = water.reduce(ee.Reducer.sum());
//clip to my study area
var clipped = sumWater.clip(studyArea);
var waterVis =
min: 0.0,
max: 2.0,
palette: ['ffffff', 'fffcb8', '0905ff'],
;
//Apply watermask- water values =2 in this layer//;
var maskedComposite = clipped.updateMask(clipped.eq(2));
// Convert the water areas to vectors.
var vectors = maskedComposite.reduceToVectors(
geometry: studyArea,
crs: maskedComposite.projection(),
scale: 30,
geometryType: 'polygon',
eightConnected: false,
labelProperty: 'water'
);
**//everything works up to here**
// Compute the intersection, for each feature in the feature collection.
var polyIntersect = polygons.map(function(feature)
var intersection = vectors.intersection(feature, ee.ErrorMargin(1));
return feature.set('Intersect': intersection.area().divide(1000 * 1000));
);
The error is get is this:
vectors.intersection is not a function
google-earth-engine
New contributor
I am trying to calculate the area of watershed within each polygon for a set of square polygons (1km*1km) in my study area. I converted a water image to a featureCollection of water polygons, it works great. I get an error when I try to intersect the square polygon layer to the water featureCollection. I also would like to export the result to a csv.
//my study area
var studyArea = ee.FeatureCollection('users/oamram/ABM_Kenya/StudyArea');
//square polygons 1km in dimensions
var polygons = ee.FeatureCollection('users/oamram/ABM_Kenya/Polygons1km');
Map.centerObject(studyArea,13);
var start = '2014-01-01';
var finish = '2014-01-31';
//get water dataset
var dataset = ee.ImageCollection('JRC/GSW1_0/MonthlyHistory')
.filter(ee.Filter.date(start, finish));
//select water layer
var water = dataset.select('water');
//identify water area
var sumWater = water.reduce(ee.Reducer.sum());
//clip to my study area
var clipped = sumWater.clip(studyArea);
var waterVis =
min: 0.0,
max: 2.0,
palette: ['ffffff', 'fffcb8', '0905ff'],
;
//Apply watermask- water values =2 in this layer//;
var maskedComposite = clipped.updateMask(clipped.eq(2));
// Convert the water areas to vectors.
var vectors = maskedComposite.reduceToVectors(
geometry: studyArea,
crs: maskedComposite.projection(),
scale: 30,
geometryType: 'polygon',
eightConnected: false,
labelProperty: 'water'
);
**//everything works up to here**
// Compute the intersection, for each feature in the feature collection.
var polyIntersect = polygons.map(function(feature)
var intersection = vectors.intersection(feature, ee.ErrorMargin(1));
return feature.set('Intersect': intersection.area().divide(1000 * 1000));
);
The error is get is this:
vectors.intersection is not a function
google-earth-engine
google-earth-engine
New contributor
New contributor
edited Apr 2 at 0:27
Vince
14.8k32849
14.8k32849
New contributor
asked Apr 1 at 19:43
oamramoamram
62
62
New contributor
New contributor
The error can't be reproduced because the features are not publicly available.
– JepsonNomad
Apr 2 at 0:29
add a comment |
The error can't be reproduced because the features are not publicly available.
– JepsonNomad
Apr 2 at 0:29
The error can't be reproduced because the features are not publicly available.
– JepsonNomad
Apr 2 at 0:29
The error can't be reproduced because the features are not publicly available.
– JepsonNomad
Apr 2 at 0:29
add a comment |
1 Answer
1
active
oldest
votes
vectors
is a FeatureCollection
and hasn't got an intersection
method. That method is for the class Feature
. This is what I'd do:
// cast vectors
vectors = ee.FeatureCollection(vectors)
// make vectors a list
var vectorList = vectors.toList(vectors.size())
var polyIntersect = polygons.iterate(function(feature, list)
list = ee.List(list)
feature = ee.Feature(feature)
var intersection = vectorList.map(function(feat)
feat = ee.Feature(feat)
var intersection = feat.intersection(feature, ee.ErrorMargin(1));
return ee.Feature(intersection).set('Intersect': intersection.area().divide(1000 * 1000))
)
return list.add(intersection)
, ee.List([]));
polyIntersect = ee.FeatureCollection(ee.List(polyIntersect).flatten())
Map.addLayer(polyIntersect)
link: https://code.earthengine.google.com/cef9d625cce4f0078c258e38ceff46f6
Isn't it faster to map the features over both feature collection, instead of using itereate? code.earthengine.google.com/deb4434e507cfcac9f45efc7e3e0ce33. Anyhow, both produce the same result. Don't forget to filter out the features which do not have an intersection area.
– Kuik
2 days ago
That's a good option too @Kuik, the code is a bit cleaner. Yes, may bemap
is a little faster thaniterate
. I made a test: code.earthengine.google.com/4d342ffe2f00aee69e11d5dbd7e33f1f. Also, I don't have to filter out because I create a new list where intersections go. But you can make an answer with your option so readers have more options, this isn't a competition but a help forum =)
– Rodrigo E. Principe
2 days ago
Thanks so much everybody. all the answers works great.
– oamram
2 days ago
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "79"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
oamram is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f317409%2fcalculating-intersect-for-two-featurecollections%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
vectors
is a FeatureCollection
and hasn't got an intersection
method. That method is for the class Feature
. This is what I'd do:
// cast vectors
vectors = ee.FeatureCollection(vectors)
// make vectors a list
var vectorList = vectors.toList(vectors.size())
var polyIntersect = polygons.iterate(function(feature, list)
list = ee.List(list)
feature = ee.Feature(feature)
var intersection = vectorList.map(function(feat)
feat = ee.Feature(feat)
var intersection = feat.intersection(feature, ee.ErrorMargin(1));
return ee.Feature(intersection).set('Intersect': intersection.area().divide(1000 * 1000))
)
return list.add(intersection)
, ee.List([]));
polyIntersect = ee.FeatureCollection(ee.List(polyIntersect).flatten())
Map.addLayer(polyIntersect)
link: https://code.earthengine.google.com/cef9d625cce4f0078c258e38ceff46f6
Isn't it faster to map the features over both feature collection, instead of using itereate? code.earthengine.google.com/deb4434e507cfcac9f45efc7e3e0ce33. Anyhow, both produce the same result. Don't forget to filter out the features which do not have an intersection area.
– Kuik
2 days ago
That's a good option too @Kuik, the code is a bit cleaner. Yes, may bemap
is a little faster thaniterate
. I made a test: code.earthengine.google.com/4d342ffe2f00aee69e11d5dbd7e33f1f. Also, I don't have to filter out because I create a new list where intersections go. But you can make an answer with your option so readers have more options, this isn't a competition but a help forum =)
– Rodrigo E. Principe
2 days ago
Thanks so much everybody. all the answers works great.
– oamram
2 days ago
add a comment |
vectors
is a FeatureCollection
and hasn't got an intersection
method. That method is for the class Feature
. This is what I'd do:
// cast vectors
vectors = ee.FeatureCollection(vectors)
// make vectors a list
var vectorList = vectors.toList(vectors.size())
var polyIntersect = polygons.iterate(function(feature, list)
list = ee.List(list)
feature = ee.Feature(feature)
var intersection = vectorList.map(function(feat)
feat = ee.Feature(feat)
var intersection = feat.intersection(feature, ee.ErrorMargin(1));
return ee.Feature(intersection).set('Intersect': intersection.area().divide(1000 * 1000))
)
return list.add(intersection)
, ee.List([]));
polyIntersect = ee.FeatureCollection(ee.List(polyIntersect).flatten())
Map.addLayer(polyIntersect)
link: https://code.earthengine.google.com/cef9d625cce4f0078c258e38ceff46f6
Isn't it faster to map the features over both feature collection, instead of using itereate? code.earthengine.google.com/deb4434e507cfcac9f45efc7e3e0ce33. Anyhow, both produce the same result. Don't forget to filter out the features which do not have an intersection area.
– Kuik
2 days ago
That's a good option too @Kuik, the code is a bit cleaner. Yes, may bemap
is a little faster thaniterate
. I made a test: code.earthengine.google.com/4d342ffe2f00aee69e11d5dbd7e33f1f. Also, I don't have to filter out because I create a new list where intersections go. But you can make an answer with your option so readers have more options, this isn't a competition but a help forum =)
– Rodrigo E. Principe
2 days ago
Thanks so much everybody. all the answers works great.
– oamram
2 days ago
add a comment |
vectors
is a FeatureCollection
and hasn't got an intersection
method. That method is for the class Feature
. This is what I'd do:
// cast vectors
vectors = ee.FeatureCollection(vectors)
// make vectors a list
var vectorList = vectors.toList(vectors.size())
var polyIntersect = polygons.iterate(function(feature, list)
list = ee.List(list)
feature = ee.Feature(feature)
var intersection = vectorList.map(function(feat)
feat = ee.Feature(feat)
var intersection = feat.intersection(feature, ee.ErrorMargin(1));
return ee.Feature(intersection).set('Intersect': intersection.area().divide(1000 * 1000))
)
return list.add(intersection)
, ee.List([]));
polyIntersect = ee.FeatureCollection(ee.List(polyIntersect).flatten())
Map.addLayer(polyIntersect)
link: https://code.earthengine.google.com/cef9d625cce4f0078c258e38ceff46f6
vectors
is a FeatureCollection
and hasn't got an intersection
method. That method is for the class Feature
. This is what I'd do:
// cast vectors
vectors = ee.FeatureCollection(vectors)
// make vectors a list
var vectorList = vectors.toList(vectors.size())
var polyIntersect = polygons.iterate(function(feature, list)
list = ee.List(list)
feature = ee.Feature(feature)
var intersection = vectorList.map(function(feat)
feat = ee.Feature(feat)
var intersection = feat.intersection(feature, ee.ErrorMargin(1));
return ee.Feature(intersection).set('Intersect': intersection.area().divide(1000 * 1000))
)
return list.add(intersection)
, ee.List([]));
polyIntersect = ee.FeatureCollection(ee.List(polyIntersect).flatten())
Map.addLayer(polyIntersect)
link: https://code.earthengine.google.com/cef9d625cce4f0078c258e38ceff46f6
answered Apr 2 at 1:47
Rodrigo E. PrincipeRodrigo E. Principe
4,17611021
4,17611021
Isn't it faster to map the features over both feature collection, instead of using itereate? code.earthengine.google.com/deb4434e507cfcac9f45efc7e3e0ce33. Anyhow, both produce the same result. Don't forget to filter out the features which do not have an intersection area.
– Kuik
2 days ago
That's a good option too @Kuik, the code is a bit cleaner. Yes, may bemap
is a little faster thaniterate
. I made a test: code.earthengine.google.com/4d342ffe2f00aee69e11d5dbd7e33f1f. Also, I don't have to filter out because I create a new list where intersections go. But you can make an answer with your option so readers have more options, this isn't a competition but a help forum =)
– Rodrigo E. Principe
2 days ago
Thanks so much everybody. all the answers works great.
– oamram
2 days ago
add a comment |
Isn't it faster to map the features over both feature collection, instead of using itereate? code.earthengine.google.com/deb4434e507cfcac9f45efc7e3e0ce33. Anyhow, both produce the same result. Don't forget to filter out the features which do not have an intersection area.
– Kuik
2 days ago
That's a good option too @Kuik, the code is a bit cleaner. Yes, may bemap
is a little faster thaniterate
. I made a test: code.earthengine.google.com/4d342ffe2f00aee69e11d5dbd7e33f1f. Also, I don't have to filter out because I create a new list where intersections go. But you can make an answer with your option so readers have more options, this isn't a competition but a help forum =)
– Rodrigo E. Principe
2 days ago
Thanks so much everybody. all the answers works great.
– oamram
2 days ago
Isn't it faster to map the features over both feature collection, instead of using itereate? code.earthengine.google.com/deb4434e507cfcac9f45efc7e3e0ce33. Anyhow, both produce the same result. Don't forget to filter out the features which do not have an intersection area.
– Kuik
2 days ago
Isn't it faster to map the features over both feature collection, instead of using itereate? code.earthengine.google.com/deb4434e507cfcac9f45efc7e3e0ce33. Anyhow, both produce the same result. Don't forget to filter out the features which do not have an intersection area.
– Kuik
2 days ago
That's a good option too @Kuik, the code is a bit cleaner. Yes, may be
map
is a little faster than iterate
. I made a test: code.earthengine.google.com/4d342ffe2f00aee69e11d5dbd7e33f1f. Also, I don't have to filter out because I create a new list where intersections go. But you can make an answer with your option so readers have more options, this isn't a competition but a help forum =)– Rodrigo E. Principe
2 days ago
That's a good option too @Kuik, the code is a bit cleaner. Yes, may be
map
is a little faster than iterate
. I made a test: code.earthengine.google.com/4d342ffe2f00aee69e11d5dbd7e33f1f. Also, I don't have to filter out because I create a new list where intersections go. But you can make an answer with your option so readers have more options, this isn't a competition but a help forum =)– Rodrigo E. Principe
2 days ago
Thanks so much everybody. all the answers works great.
– oamram
2 days ago
Thanks so much everybody. all the answers works great.
– oamram
2 days ago
add a comment |
oamram is a new contributor. Be nice, and check out our Code of Conduct.
oamram is a new contributor. Be nice, and check out our Code of Conduct.
oamram is a new contributor. Be nice, and check out our Code of Conduct.
oamram is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f317409%2fcalculating-intersect-for-two-featurecollections%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The error can't be reproduced because the features are not publicly available.
– JepsonNomad
Apr 2 at 0:29