arcgis 0.1.3

Type-safe Rust SDK for the ArcGIS REST API with compile-time guarantees
Documentation
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
//! Tests for Map Service types and client.

mod common;

use arcgis::{
    ApiKeyAuth, ArcGISClient, ExportMapParams, ExportResult, ExportTarget, GeometryType,
    IdentifyParams, ImageFormat, LayerOperation, LayerSelection, MapServiceClient, TileCoordinate,
    TimeRelation,
};

#[test]
fn test_image_format_serialization() -> anyhow::Result<()> {
    common::init_tracing();
    tracing::info!("test_image_format_serialization: Starting");

    tracing::info!("test_image_format_serialization: Testing Png format");
    let png = ImageFormat::Png;
    let serialized = serde_json::to_string(&png)?;
    assert_eq!(serialized, "\"png\"");

    tracing::info!("test_image_format_serialization: Testing Png32 format");
    let png32 = ImageFormat::Png32;
    let serialized = serde_json::to_string(&png32)?;
    assert_eq!(serialized, "\"png32\"");

    tracing::info!("test_image_format_serialization: Testing Jpg format");
    let jpg = ImageFormat::Jpg;
    let serialized = serde_json::to_string(&jpg)?;
    assert_eq!(serialized, "\"jpg\"");

    tracing::info!("test_image_format_serialization: Testing Pdf format");
    let pdf = ImageFormat::Pdf;
    let serialized = serde_json::to_string(&pdf)?;
    assert_eq!(serialized, "\"pdf\"");

    tracing::info!("test_image_format_serialization: Completed");
    Ok(())
}

#[test]
fn test_image_format_default() -> anyhow::Result<()> {
    common::init_tracing();
    tracing::info!("test_image_format_default: Starting");

    tracing::info!("test_image_format_default: Checking default format");
    let format = ImageFormat::default();

    tracing::info!(
        format = ?format,
        "test_image_format_default: Verifying default"
    );
    assert_eq!(format, ImageFormat::Png);

    tracing::info!("test_image_format_default: Completed");
    Ok(())
}

#[test]
fn test_layer_operation_as_str() -> anyhow::Result<()> {
    common::init_tracing();
    tracing::info!("test_layer_operation_as_str: Starting");

    tracing::info!("test_layer_operation_as_str: Testing layer operation string conversions");
    assert_eq!(LayerOperation::Show.as_str(), "show");
    assert_eq!(LayerOperation::Hide.as_str(), "hide");
    assert_eq!(LayerOperation::Include.as_str(), "include");
    assert_eq!(LayerOperation::Exclude.as_str(), "exclude");

    tracing::info!("test_layer_operation_as_str: Completed");
    Ok(())
}

#[test]
fn test_time_relation_serialization() -> anyhow::Result<()> {
    common::init_tracing();
    tracing::info!("test_time_relation_serialization: Starting");

    tracing::info!("test_time_relation_serialization: Testing Overlaps serialization");
    let overlaps = TimeRelation::Overlaps;
    let serialized = serde_json::to_string(&overlaps)?;
    assert_eq!(serialized, "\"esriTimeRelationOverlaps\"");

    tracing::info!("test_time_relation_serialization: Testing After serialization");
    let after = TimeRelation::After;
    let serialized = serde_json::to_string(&after)?;
    assert_eq!(serialized, "\"esriTimeRelationAfter\"");

    tracing::info!("test_time_relation_serialization: Testing Before serialization");
    let before = TimeRelation::Before;
    let serialized = serde_json::to_string(&before)?;
    assert_eq!(serialized, "\"esriTimeRelationBefore\"");

    tracing::info!("test_time_relation_serialization: Completed");
    Ok(())
}

#[test]
fn test_time_relation_default() -> anyhow::Result<()> {
    common::init_tracing();
    tracing::info!("test_time_relation_default: Starting");

    tracing::info!("test_time_relation_default: Checking default relation");
    let relation = TimeRelation::default();

    tracing::info!(
        relation = ?relation,
        "test_time_relation_default: Verifying default"
    );
    assert_eq!(relation, TimeRelation::Overlaps);

    tracing::info!("test_time_relation_default: Completed");
    Ok(())
}

#[test]
fn test_layer_selection_serialization() -> anyhow::Result<()> {
    common::init_tracing();
    tracing::info!("test_layer_selection_serialization: Starting");

    tracing::info!("test_layer_selection_serialization: Testing Top serialization");
    let top = LayerSelection::Top;
    let serialized = serde_json::to_string(&top)?;
    assert_eq!(serialized, "\"top\"");

    tracing::info!("test_layer_selection_serialization: Testing Visible serialization");
    let visible = LayerSelection::Visible;
    let serialized = serde_json::to_string(&visible)?;
    assert_eq!(serialized, "\"visible\"");

    tracing::info!("test_layer_selection_serialization: Testing All serialization");
    let all = LayerSelection::All;
    let serialized = serde_json::to_string(&all)?;
    assert_eq!(serialized, "\"all\"");

    tracing::info!("test_layer_selection_serialization: Completed");
    Ok(())
}

#[test]
fn test_layer_selection_default() -> anyhow::Result<()> {
    common::init_tracing();
    tracing::info!("test_layer_selection_default: Starting");

    tracing::info!("test_layer_selection_default: Checking default selection");
    let selection = LayerSelection::default();

    tracing::info!(
        selection = ?selection,
        "test_layer_selection_default: Verifying default"
    );
    assert_eq!(selection, LayerSelection::Visible);

    tracing::info!("test_layer_selection_default: Completed");
    Ok(())
}

#[test]
fn test_export_map_params_builder() -> anyhow::Result<()> {
    common::init_tracing();
    tracing::info!("test_export_map_params_builder: Starting");

    tracing::info!("test_export_map_params_builder: Building ExportMapParams");
    let params = ExportMapParams::builder()
        .bbox("-118.0,34.0,-117.0,35.0")
        .size("800,600")
        .dpi(96)
        .format(ImageFormat::Png32)
        .transparent(true)
        .build()
        .map_err(|e| arcgis::BuilderError::from(e.to_string()))?;

    tracing::info!(
        bbox = %params.bbox(),
        size = ?params.size(),
        dpi = ?params.dpi(),
        format = ?params.format(),
        transparent = ?params.transparent(),
        "test_export_map_params_builder: Verifying params"
    );
    assert_eq!(*params.bbox(), "-118.0,34.0,-117.0,35.0");
    assert_eq!(*params.size(), Some("800,600".to_string()));
    assert_eq!(*params.dpi(), Some(96));
    assert_eq!(*params.format(), Some(ImageFormat::Png32));
    assert_eq!(*params.transparent(), Some(true));

    tracing::info!("test_export_map_params_builder: Completed");
    Ok(())
}

#[test]
fn test_export_map_params_default() -> anyhow::Result<()> {
    common::init_tracing();
    tracing::info!("test_export_map_params_default: Starting");

    tracing::info!("test_export_map_params_default: Creating default params");
    let params = ExportMapParams::default();

    tracing::info!(
        bbox = %params.bbox(),
        size = ?params.size(),
        dpi = ?params.dpi(),
        format = ?params.format(),
        transparent = ?params.transparent(),
        "test_export_map_params_default: Verifying defaults"
    );
    assert_eq!(*params.bbox(), "");
    assert_eq!(*params.size(), Some("400,400".to_string()));
    assert_eq!(*params.dpi(), Some(96));
    assert_eq!(*params.format(), Some(ImageFormat::Png));
    assert_eq!(*params.transparent(), Some(false));

    tracing::info!("test_export_map_params_default: Completed");
    Ok(())
}

#[test]
fn test_identify_params_builder() -> anyhow::Result<()> {
    common::init_tracing();
    tracing::info!("test_identify_params_builder: Starting");

    tracing::info!("test_identify_params_builder: Building IdentifyParams");
    let params = IdentifyParams::builder()
        .geometry("{\"x\":-118.0,\"y\":34.0}")
        .geometry_type(GeometryType::Point)
        .tolerance(5)
        .map_extent("-120,32,-116,36")
        .image_display("800,600,96")
        .layers(LayerSelection::Visible)
        .build()
        .map_err(|e| arcgis::BuilderError::from(e.to_string()))?;

    tracing::info!(
        geometry = %params.geometry(),
        geometry_type = ?params.geometry_type(),
        tolerance = params.tolerance(),
        map_extent = %params.map_extent(),
        image_display = %params.image_display(),
        layers = ?params.layers(),
        "test_identify_params_builder: Verifying params"
    );
    assert_eq!(params.geometry(), "{\"x\":-118.0,\"y\":34.0}");
    assert_eq!(*params.geometry_type(), GeometryType::Point);
    assert_eq!(*params.tolerance(), 5);
    assert_eq!(params.map_extent(), "-120,32,-116,36");
    assert_eq!(params.image_display(), "800,600,96");
    assert_eq!(*params.layers(), Some(LayerSelection::Visible));

    tracing::info!("test_identify_params_builder: Completed");
    Ok(())
}

#[test]
fn test_tile_coordinate_creation() -> anyhow::Result<()> {
    common::init_tracing();
    tracing::info!("test_tile_coordinate_creation: Starting");

    tracing::info!("test_tile_coordinate_creation: Creating TileCoordinate");
    let coord = TileCoordinate::new(5, 10, 15);

    tracing::info!(
        level = coord.level(),
        row = coord.row(),
        col = coord.col(),
        "test_tile_coordinate_creation: Verifying coordinate"
    );
    assert_eq!(*coord.level(), 5);
    assert_eq!(*coord.row(), 10);
    assert_eq!(*coord.col(), 15);

    tracing::info!("test_tile_coordinate_creation: Completed");
    Ok(())
}

#[test]
fn test_export_target_helpers() -> anyhow::Result<()> {
    common::init_tracing();
    tracing::info!("test_export_target_helpers: Starting");

    tracing::info!("test_export_target_helpers: Testing Path target");
    let path_target = ExportTarget::to_path("/tmp/map.png");
    match path_target {
        ExportTarget::Path(p) => {
            tracing::info!(path = %p.display(), "test_export_target_helpers: Path target created");
            assert_eq!(p.to_str().unwrap(), "/tmp/map.png");
        }
        _ => anyhow::bail!("Expected Path variant"),
    }

    tracing::info!("test_export_target_helpers: Testing Bytes target");
    let bytes_target = ExportTarget::to_bytes();
    match bytes_target {
        ExportTarget::Bytes => {
            tracing::info!("test_export_target_helpers: Bytes target created");
        }
        _ => anyhow::bail!("Expected Bytes variant"),
    }

    tracing::info!("test_export_target_helpers: Completed");
    Ok(())
}

#[test]
fn test_export_result_helpers() -> anyhow::Result<()> {
    common::init_tracing();
    tracing::info!("test_export_result_helpers: Starting");

    use std::path::PathBuf;

    tracing::info!("test_export_result_helpers: Testing Path result");
    let path_result = ExportResult::Path(PathBuf::from("/tmp/map.png"));
    tracing::info!(
        path = ?path_result.path(),
        "test_export_result_helpers: Verifying Path result"
    );
    assert_eq!(
        path_result.path().unwrap().to_str().unwrap(),
        "/tmp/map.png"
    );
    assert!(path_result.bytes().is_none());
    assert!(path_result.written().is_none());

    tracing::info!("test_export_result_helpers: Testing Bytes result");
    let bytes_result = ExportResult::Bytes(vec![1, 2, 3, 4, 5]);
    tracing::info!(
        bytes_len = ?bytes_result.bytes().map(|b| b.len()),
        "test_export_result_helpers: Verifying Bytes result"
    );
    assert!(bytes_result.path().is_none());
    assert_eq!(bytes_result.bytes().unwrap().len(), 5);
    assert!(bytes_result.written().is_none());

    tracing::info!("test_export_result_helpers: Testing Written result");
    let written_result = ExportResult::Written(1024);
    tracing::info!(
        bytes_written = ?written_result.written(),
        "test_export_result_helpers: Verifying Written result"
    );
    assert!(written_result.path().is_none());
    assert!(written_result.bytes().is_none());
    assert_eq!(written_result.written().unwrap(), 1024);

    tracing::info!("test_export_result_helpers: Completed");
    Ok(())
}

#[test]
fn test_map_service_client_creation() -> anyhow::Result<()> {
    common::init_tracing();
    tracing::info!("test_map_service_client_creation: Starting");

    tracing::info!("test_map_service_client_creation: Creating API key auth");
    let auth = ApiKeyAuth::new("test_key");
    let client = ArcGISClient::new(auth);

    tracing::info!("test_map_service_client_creation: Creating MapServiceClient");
    let map_service = MapServiceClient::new(
        "https://services.arcgis.com/test/arcgis/rest/services/World/MapServer",
        &client,
    );

    // Just verify it compiles and constructs correctly
    drop(map_service);

    tracing::info!("test_map_service_client_creation: Completed");
    Ok(())
}

#[test]
fn test_export_builder_fluent_api() -> anyhow::Result<()> {
    common::init_tracing();
    tracing::info!("test_export_builder_fluent_api: Starting");

    tracing::info!("test_export_builder_fluent_api: Creating test client");
    let auth = ApiKeyAuth::new("test_key");
    let client = ArcGISClient::new(auth);
    let map_service = MapServiceClient::new(
        "https://services.arcgis.com/test/arcgis/rest/services/World/MapServer",
        &client,
    );

    // Test builder pattern compiles (don't execute)
    tracing::info!("test_export_builder_fluent_api: Building export request");
    let builder = map_service
        .export()
        .bbox("-118.0,34.0,-117.0,35.0")
        .size(800, 600)
        .format(ImageFormat::Png32)
        .transparent(true)
        .dpi(96);

    // Verify builder exists
    drop(builder);

    tracing::info!("test_export_builder_fluent_api: Completed");
    Ok(())
}

#[test]
fn test_layer_visibility_formatting() -> anyhow::Result<()> {
    common::init_tracing();
    tracing::info!("test_layer_visibility_formatting: Starting");

    tracing::info!("test_layer_visibility_formatting: Creating test client");
    let auth = ApiKeyAuth::new("test_key");
    let client = ArcGISClient::new(auth);
    let map_service = MapServiceClient::new(
        "https://services.arcgis.com/test/arcgis/rest/services/World/MapServer",
        &client,
    );

    // Test layer_visibility method compiles with different operations
    tracing::info!("test_layer_visibility_formatting: Testing Show operation");
    let show_builder = map_service
        .export()
        .bbox("-118.0,34.0,-117.0,35.0")
        .layer_visibility(LayerOperation::Show, &[0, 1, 2]);

    drop(show_builder);

    tracing::info!("test_layer_visibility_formatting: Testing Hide operation");
    let hide_builder = map_service
        .export()
        .bbox("-118.0,34.0,-117.0,35.0")
        .layer_visibility(LayerOperation::Hide, &[3, 4]);

    drop(hide_builder);

    tracing::info!("test_layer_visibility_formatting: Completed");
    Ok(())
}