-
Notifications
You must be signed in to change notification settings - Fork 0
/
googleearthtest.js
164 lines (137 loc) · 3.52 KB
/
googleearthtest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// Load the Romagna FeatureCollection
for google earth engine code editor
var romagna = ee.FeatureCollection('projects/erfloodprevention/assets/romagna_italy');
// Center map on Romagna region
Map.centerObject(romagna, 8);
// Style the FeatureCollection
var romagnaStyle = {
color: 'FF0000', // Red outline
fillColor: '00000000', // Transparent fill
width: 2
};
// Add the styled layer to the map
Map.addLayer(romagna, romagnaStyle, 'Romagna Region');
// Add different basemap layers
Map.setOptions('HYBRID');
// Create a custom UI panel
var panel = ui.Panel({
style: {
width: '300px',
padding: '10px'
}
});
// Add a title
panel.add(ui.Label({
value: 'Romagna Region Analysis',
style: {
fontSize: '20px',
fontWeight: 'bold',
margin: '10px 0'
}
}));
// Calculate and display area
var area = romagna.geometry().area().divide(1000000); // Convert to km²
area.evaluate(function(result) {
panel.add(ui.Label('Total Area: ' + result.toFixed(2) + ' km²'));
});
// Add feature count
var count = romagna.size();
count.evaluate(function(result) {
panel.add(ui.Label('Number of Features: ' + result));
});
// Add property names
var properties = romagna.first().propertyNames();
properties.evaluate(function(props) {
panel.add(ui.Label('Properties:', {fontWeight: 'bold', margin: '10px 0'}));
props.forEach(function(prop) {
panel.add(ui.Label('- ' + prop));
});
});
// Add legend
var legend = ui.Panel({
style: {
padding: '8px 15px',
position: 'bottom-left'
}
});
var legendTitle = ui.Label({
value: 'Legend',
style: {
fontWeight: 'bold',
fontSize: '16px',
margin: '0 0 4px 0',
padding: '0'
}
});
legend.add(legendTitle);
var makeRow = function(color, name) {
var colorBox = ui.Label({
style: {
backgroundColor: color,
padding: '8px',
margin: '0 0 4px 0'
}
});
var description = ui.Label({
value: name,
style: {margin: '0 0 4px 6px'}
});
return ui.Panel({
widgets: [colorBox, description],
layout: ui.Panel.Layout.Flow('horizontal')
});
};
legend.add(makeRow('#FF0000', 'Region Boundary'));
// Add layer controls
var layerPanel = ui.Panel({
style: {
position: 'top-right',
padding: '10px'
}
});
// Add export button
var exportButton = ui.Button({
label: 'Export to Drive',
onClick: function() {
Export.table.toDrive({
collection: romagna,
description: 'Romagna_Region_Export',
fileFormat: 'GeoJSON'
});
}
});
panel.add(ui.Label('', {margin: '10px 0'})); // Spacer
panel.add(exportButton);
// Add basemap selector
var basemapSelector = ui.Select({
items: ['HYBRID', 'SATELLITE', 'ROADMAP', 'TERRAIN'],
value: 'HYBRID',
onChange: function(value) {
Map.setOptions(value);
},
style: {margin: '10px 0'}
});
panel.add(ui.Label('Basemap:', {margin: '10px 0 0 0'}));
panel.add(basemapSelector);
// Add panels to the map
Map.add(panel);
Map.add(legend);
// Add scale bar and north arrow
Map.setControlVisibility({
scaleControl: true,
zoomControl: true,
fullscreenControl: true
});
// Print some basic statistics to the console
print('Romagna Region Statistics:', {
'Dataset': 'projects/erfloodprevention/assets/romagna_italy',
'Number of Features': romagna.size(),
'Geometry Type': romagna.first().geometry().type(),
'CRS': romagna.first().geometry().projection()
});
// Function to get feature properties
var getFeatureProperties = function(feature) {
return feature.toDictionary();
};
// Print first feature properties
print('First Feature Properties:', romagna.first().toDictionary());