Send feedback
ee.FeatureCollection.merge
Stay organized with collections
Save and categorize content based on your preferences.
Merges two collections into one. The result has all the elements that were in either collection.
Elements from the first collection will have IDs prefixed with "1" and elements from the second collection will have IDs prefixed with "2 ".
Note: If many collections need to be merged, consider placing them all in a collection and using FeatureCollection.flatten() instead. Repeated use of FeatureCollection.merge() will result in increasingly long element IDs and reduced performance.
Usage Returns FeatureCollection. merge (collection2)
FeatureCollection
Argument Type Details this: collection1
FeatureCollection The first collection to merge. collection2
FeatureCollection The second collection to merge.
Examples
Code Editor (JavaScript)
// FeatureCollection of points representing forest cover.
var fcForest = ee . FeatureCollection ([
ee . Feature ( ee . Geometry . Point ([ - 122.248 , 37.238 ]),
{ 'id' : 0 , 'cover_class' : 'forest' }),
ee . Feature ( ee . Geometry . Point ([ - 122.204 , 37.222 ]),
{ 'id' : 1 , 'cover_class' : 'forest' }),
ee . Feature ( ee . Geometry . Point ([ - 122.110 , 37.199 ]),
{ 'id' : 2 , 'cover_class' : 'forest' })
]);
// FeatureCollection of points representing urban cover.
var fcUrban = ee . FeatureCollection ([
ee . Feature ( ee . Geometry . Point ([ - 121.953 , 37.372 ]),
{ 'id' : 0 , 'cover_class' : 'urban' }),
ee . Feature ( ee . Geometry . Point ([ - 121.861 , 37.308 ]),
{ 'id' : 1 , 'cover_class' : 'urban' }),
ee . Feature ( ee . Geometry . Point ([ - 121.984 , 37.372 ]),
{ 'id' : 2 , 'cover_class' : 'urban' })
]);
// Merge the two FeatureCollections into one.
var fcMerged = fcForest . merge ( fcUrban );
// Display FeatureCollections on the map.
Map . setCenter ( - 122.034 , 37.296 , 11 );
Map . addLayer ( fcForest , { color : 'green' }, 'Forest points' );
Map . addLayer ( fcUrban , { color : 'grey' }, 'Urban points' );
Map . addLayer ( fcMerged , { color : 'yellow' }, 'Protected areas merged' );
Python setup
See the
Python Environment page for information on the Python API and using
geemap
for interactive development.
import ee
import geemap.core as geemap
Colab (Python)
# FeatureCollection of points representing forest cover.
fc_forest = ee . FeatureCollection ([
ee . Feature (
ee . Geometry . Point ([ - 122.248 , 37.238 ]),
{
'id' : 0 ,
'cover_class' : 'forest' ,
'id' : 0 ,
'cover_class' : 'forest' ,
},
),
ee . Feature (
ee . Geometry . Point ([ - 122.204 , 37.222 ]),
{
'id' : 1 ,
'cover_class' : 'forest' ,
'id' : 1 ,
'cover_class' : 'forest' ,
},
),
ee . Feature (
ee . Geometry . Point ([ - 122.110 , 37.199 ]),
{
'id' : 2 ,
'cover_class' : 'forest' ,
'id' : 2 ,
'cover_class' : 'forest' ,
},
),
])
# FeatureCollection of points representing urban cover.
fc_urban = ee . FeatureCollection ([
ee . Feature (
ee . Geometry . Point ([ - 121.953 , 37.372 ]),
{ 'id' : 0 , 'cover_class' : 'urban' , 'id' : 0 , 'cover_class' : 'urban' },
),
ee . Feature (
ee . Geometry . Point ([ - 121.861 , 37.308 ]),
{ 'id' : 1 , 'cover_class' : 'urban' , 'id' : 1 , 'cover_class' : 'urban' },
),
ee . Feature (
ee . Geometry . Point ([ - 121.984 , 37.372 ]),
{ 'id' : 2 , 'cover_class' : 'urban' , 'id' : 2 , 'cover_class' : 'urban' },
),
])
# Merge the two FeatureCollections into one.
fc_merged = fc_forest . merge ( fc_urban )
# Display FeatureCollections on the map.
m = geemap . Map ()
m . set_center ( - 122.034 , 37.296 , 11 )
m . add_layer ( fc_forest , { 'color' : 'green' }, 'Forest points' )
m . add_layer ( fc_urban , { 'color' : 'grey' }, 'Urban points' )
m . add_layer ( fc_merged , { 'color' : 'yellow' }, 'Protected areas merged' )
m
Send feedback
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-10-06 UTC.
Need to tell us more?
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-10-06 UTC."],[[["`FeatureCollection.merge()` combines two FeatureCollections into a single FeatureCollection containing all elements from both."],["Elements from the input collections retain their original properties but are given new IDs prefixed with \"1*\" and \"2*\" to distinguish their source."],["For merging multiple collections, using `FeatureCollection.flatten()` on a collection containing all of them is recommended for better performance."],["Repeatedly using `FeatureCollection.merge()` can lead to decreased performance and excessively long element IDs."]]],[]]