forked from lukeroth/gdal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
osr.go
1199 lines (1066 loc) · 32 KB
/
osr.go
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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package gdal
/*
#include "go_gdal.h"
#include "gdal_version.h"
#include "ogr_srs_api.h"
*/
import "C"
import (
"reflect"
"unsafe"
)
type AxisMappingStrategy uint32
const (
OAMS_TraditionalGisOrder = AxisMappingStrategy(C.OAMS_TRADITIONAL_GIS_ORDER)
OAMS_AuthorityCompliant = AxisMappingStrategy(C.OAMS_AUTHORITY_COMPLIANT)
OAMS_Custom = AxisMappingStrategy(C.OAMS_CUSTOM)
)
/* -------------------------------------------------------------------- */
/* Spatial reference functions. */
/* -------------------------------------------------------------------- */
type SpatialReference struct {
cval C.OGRSpatialReferenceH
}
// Create a new SpatialReference
func CreateSpatialReference(wkt string) SpatialReference {
cString := C.CString(wkt)
defer C.free(unsafe.Pointer(cString))
sr := C.OSRNewSpatialReference(cString)
return SpatialReference{sr}
}
func (sr SpatialReference) SetAxisMappingStrategy(strategy AxisMappingStrategy) {
C.OSRSetAxisMappingStrategy(sr.cval, C.OSRAxisMappingStrategy(strategy))
}
// Initialize SRS based on WKT string
func (sr SpatialReference) FromWKT(wkt string) error {
cString := C.CString(wkt)
defer C.free(unsafe.Pointer(cString))
return OGRErr(C.OSRImportFromWkt(sr.cval, &cString))
}
// Export coordinate system to WKT
func (sr SpatialReference) ToWKT() (string, error) {
var p *C.char
err := OGRErr(C.OSRExportToWkt(sr.cval, &p))
wkt := C.GoString(p)
return wkt, err
}
// Export coordinate system to a nicely formatted WKT string
func (sr SpatialReference) ToPrettyWKT(simplify bool) (string, error) {
var p *C.char
err := OGRErr(C.OSRExportToPrettyWkt(
sr.cval, &p, BoolToCInt(simplify),
))
wkt := C.GoString(p)
return wkt, err
}
// Initialize SRS based on EPSG code
func (sr SpatialReference) FromEPSG(code int) error {
return OGRErr(C.OSRImportFromEPSG(sr.cval, C.int(code)))
}
// Initialize SRS based on EPSG code, using EPSG lat/long ordering
func (sr SpatialReference) FromEPSGA(code int) error {
return OGRErr(C.OSRImportFromEPSGA(sr.cval, C.int(code)))
}
// Destroy the spatial reference
func (sr SpatialReference) Destroy() {
C.OSRDestroySpatialReference(sr.cval)
}
// Make a duplicate of this spatial reference
func (sr SpatialReference) Clone() SpatialReference {
newSR := C.OSRClone(sr.cval)
return SpatialReference{newSR}
}
// Make a duplicate of the GEOGCS node of this spatial reference
func (sr SpatialReference) CloneGeogCS() SpatialReference {
newSR := C.OSRCloneGeogCS(sr.cval)
return SpatialReference{newSR}
}
// Increments the reference count by one, returning reference count
func (sr SpatialReference) Reference() int {
count := C.OSRReference(sr.cval)
return int(count)
}
// Decrements the reference count by one, returning reference count
func (sr SpatialReference) Dereference() int {
count := C.OSRDereference(sr.cval)
return int(count)
}
// Decrements the reference count by one and destroy if zero
func (sr SpatialReference) Release() {
C.OSRRelease(sr.cval)
}
// Validate spatial reference tokens
func (sr SpatialReference) Validate() error {
return OGRErr(C.OSRValidate(sr.cval))
}
// Import PROJ.4 coordinate string
func (sr SpatialReference) FromProj4(input string) error {
cString := C.CString(input)
defer C.free(unsafe.Pointer(cString))
return OGRErr(C.OSRImportFromProj4(sr.cval, cString))
}
// Export coordinate system in PROJ.4 format
func (sr SpatialReference) ToProj4() (string, error) {
var p *C.char
err := OGRErr(C.OSRExportToProj4(sr.cval, &p))
proj4 := C.GoString(p)
return proj4, err
}
// Import coordinate system from ESRI .prj formats
func (sr SpatialReference) FromESRI(input string) error {
cString := C.CString(input)
defer C.free(unsafe.Pointer(cString))
return OGRErr(C.OSRImportFromProj4(sr.cval, cString))
}
// Import coordinate system from PCI projection definition
func (sr SpatialReference) FromPCI(proj, units string, params []float64) error {
cProj := C.CString(proj)
defer C.free(unsafe.Pointer(cProj))
cUnits := C.CString(units)
defer C.free(unsafe.Pointer(cUnits))
return OGRErr(C.OSRImportFromPCI(
sr.cval,
cProj,
cUnits,
(*C.double)(unsafe.Pointer(¶ms[0])),
))
}
// Import coordinate system from USGS projection definition
func (sr SpatialReference) FromUSGS(projsys, zone int, params []float64, datum int) error {
return OGRErr(C.OSRImportFromUSGS(
sr.cval,
C.long(projsys),
C.long(zone),
(*C.double)(unsafe.Pointer(¶ms[0])),
C.long(datum),
))
}
// Import coordinate system from XML format (GML only currently)
func (sr SpatialReference) FromXML(xml string) error {
cXml := C.CString(xml)
defer C.free(unsafe.Pointer(cXml))
return OGRErr(C.OSRImportFromXML(sr.cval, cXml))
}
// Import coordinate system from ERMapper projection definitions
func (sr SpatialReference) FromERM(proj, datum, units string) error {
cProj := C.CString(proj)
defer C.free(unsafe.Pointer(cProj))
cDatum := C.CString(datum)
defer C.free(unsafe.Pointer(cDatum))
cUnits := C.CString(units)
defer C.free(unsafe.Pointer(cUnits))
return OGRErr(C.OSRImportFromERM(sr.cval, cProj, cDatum, cUnits))
}
// Import coordinate system from a URL
func (sr SpatialReference) FromURL(url string) error {
cURL := C.CString(url)
defer C.free(unsafe.Pointer(cURL))
return OGRErr(C.OSRImportFromXML(sr.cval, cURL))
}
// Export coordinate system in PCI format
func (sr SpatialReference) ToPCI() (proj, units string, params []float64, errVal error) {
var p, u *C.char
err := OGRErr(C.OSRExportToPCI(
sr.cval, &p, &u, (**C.double)(unsafe.Pointer(¶ms[0])),
))
header := (*reflect.SliceHeader)(unsafe.Pointer(¶ms))
header.Cap = 17
header.Len = 17
defer C.free(unsafe.Pointer(p))
defer C.free(unsafe.Pointer(u))
return C.GoString(p), C.GoString(u), params, err
}
// Export coordinate system to USGS GCTP projection definition
func (sr SpatialReference) ToUSGS() (proj, zone int, params []float64, datum int, errVal error) {
err := OGRErr(C.OSRExportToUSGS(
sr.cval,
(*C.long)(unsafe.Pointer(&proj)),
(*C.long)(unsafe.Pointer(&zone)),
(**C.double)(unsafe.Pointer(¶ms[0])),
(*C.long)(unsafe.Pointer(&datum)),
))
header := (*reflect.SliceHeader)(unsafe.Pointer(¶ms))
header.Cap = 15
header.Len = 15
return proj, zone, params, datum, err
}
// Export coordinate system in XML format
func (sr SpatialReference) ToXML() (xml string, errVal error) {
var x *C.char
err := OGRErr(C.OSRExportToXML(sr.cval, &x, nil))
defer C.free(unsafe.Pointer(x))
return C.GoString(x), err
}
// Export coordinate system in Mapinfo style CoordSys format
func (sr SpatialReference) ToMICoordSys() (output string, errVal error) {
var x *C.char
err := OGRErr(C.OSRExportToMICoordSys(sr.cval, &x))
defer C.free(unsafe.Pointer(x))
return C.GoString(x), err
}
// Export coordinate system in ERMapper format
// Unimplemented: ToERM
// Convert in place to ESRI WKT format
func (sr SpatialReference) MorphToESRI() error {
return OGRErr(C.OSRMorphToESRI(sr.cval))
}
// Convert in place from ESRI WKT format
func (sr SpatialReference) MorphFromESRI() error {
return OGRErr(C.OSRMorphFromESRI(sr.cval))
}
// Fetch indicated attribute of named node
func (sr SpatialReference) AttrValue(key string, child int) (value string, ok bool) {
cKey := C.CString(key)
defer C.free(unsafe.Pointer(cKey))
val := C.OSRGetAttrValue(sr.cval, cKey, C.int(child))
return C.GoString(val), val != nil
}
// Set attribute value in spatial reference
func (sr SpatialReference) SetAttrValue(path, value string) error {
cPath := C.CString(path)
defer C.free(unsafe.Pointer(cPath))
cValue := C.CString(value)
defer C.free(unsafe.Pointer(cValue))
return OGRErr(C.OSRSetAttrValue(sr.cval, cPath, cValue))
}
// Set the angular units for the geographic coordinate system
func (sr SpatialReference) SetAngularUnits(units string, radians float64) error {
cUnits := C.CString(units)
defer C.free(unsafe.Pointer(cUnits))
return OGRErr(C.OSRSetAngularUnits(sr.cval, cUnits, C.double(radians)))
}
// Fetch the angular units for the geographic coordinate system
func (sr SpatialReference) AngularUnits() (string, float64) {
var x *C.char
factor := C.OSRGetAngularUnits(sr.cval, &x)
defer C.free(unsafe.Pointer(x))
return C.GoString(x), float64(factor)
}
// Set the linear units for the projection
func (sr SpatialReference) SetLinearUnits(name string, toMeters float64) error {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
return OGRErr(C.OSRSetLinearUnits(sr.cval, cName, C.double(toMeters)))
}
// Set the linear units for the target node
func (sr SpatialReference) SetTargetLinearUnits(target, units string, toMeters float64) error {
cTarget := C.CString(target)
defer C.free(unsafe.Pointer(cTarget))
cUnits := C.CString(units)
defer C.free(unsafe.Pointer(cUnits))
return OGRErr(C.OSRSetTargetLinearUnits(sr.cval, cTarget, cUnits, C.double(toMeters)))
}
// Set the linear units for the target node and update all existing linear parameters
func (sr SpatialReference) SetLinearUnitsAndUpdateParameters(name string, toMeters float64) error {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
return OGRErr(C.OSRSetLinearUnitsAndUpdateParameters(sr.cval, cName, C.double(toMeters)))
}
// Fetch linear projection units
func (sr SpatialReference) LinearUnits() (string, float64) {
var x *C.char
factor := C.OSRGetLinearUnits(sr.cval, &x)
defer C.free(unsafe.Pointer(x))
return C.GoString(x), float64(factor)
}
// Fetch linear units for target
func (sr SpatialReference) TargetLinearUnits(target string) (string, float64) {
cTarget := C.CString(target)
defer C.free(unsafe.Pointer(cTarget))
var x *C.char
factor := C.OSRGetTargetLinearUnits(sr.cval, cTarget, &x)
defer C.free(unsafe.Pointer(x))
return C.GoString(x), float64(factor)
}
// Fetch prime meridian information
func (sr SpatialReference) PrimeMeridian() (string, float64) {
var x *C.char
offset := C.OSRGetPrimeMeridian(sr.cval, &x)
defer C.free(unsafe.Pointer(x))
return C.GoString(x), float64(offset)
}
// Return true if geographic coordinate system
func (sr SpatialReference) IsGeographic() bool {
val := C.OSRIsGeographic(sr.cval)
return val != 0
}
// Return true if local coordinate system
func (sr SpatialReference) IsLocal() bool {
val := C.OSRIsLocal(sr.cval)
return val != 0
}
// Return true if projected coordinate system
func (sr SpatialReference) IsProjected() bool {
val := C.OSRIsProjected(sr.cval)
return val != 0
}
// Return true if compound coordinate system
func (sr SpatialReference) IsCompound() bool {
val := C.OSRIsCompound(sr.cval)
return val != 0
}
// Return true if geocentric coordinate system
func (sr SpatialReference) IsGeocentric() bool {
val := C.OSRIsGeocentric(sr.cval)
return val != 0
}
// Return true if vertical coordinate system
func (sr SpatialReference) IsVertical() bool {
val := C.OSRIsVertical(sr.cval)
return val != 0
}
// Return true if the geographic coordinate systems match
func (sr SpatialReference) IsSameGeographicCS(other SpatialReference) bool {
val := C.OSRIsSameGeogCS(sr.cval, other.cval)
return val != 0
}
// Return true if the vertical coordinate systems match
func (sr SpatialReference) IsSameVerticalCS(other SpatialReference) bool {
val := C.OSRIsSameVertCS(sr.cval, other.cval)
return val != 0
}
// Return true if the coordinate systems describe the same system
func (sr SpatialReference) IsSame(other SpatialReference) bool {
val := C.OSRIsSame(sr.cval, other.cval)
return val != 0
}
// Set the user visible local CS name
func (sr SpatialReference) SetLocalCS(name string) error {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
return OGRErr(C.OSRSetLocalCS(sr.cval, cName))
}
// Set the user visible projected CS name
func (sr SpatialReference) SetProjectedCS(name string) error {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
return OGRErr(C.OSRSetProjCS(sr.cval, cName))
}
// Set the user visible geographic CS name
func (sr SpatialReference) SetGeocentricCS(name string) error {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
return OGRErr(C.OSRSetGeocCS(sr.cval, cName))
}
// Set geographic CS based on well known name
func (sr SpatialReference) SetWellKnownGeographicCS(name string) error {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
return OGRErr(C.OSRSetWellKnownGeogCS(sr.cval, cName))
}
// Set spatial reference from various text formats
func (sr SpatialReference) SetFromUserInput(name string) error {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
return OGRErr(C.OSRSetFromUserInput(sr.cval, cName))
}
// Copy geographic CS from another spatial reference
func (sr SpatialReference) CopyGeographicCSFrom(other SpatialReference) error {
return OGRErr(C.OSRCopyGeogCSFrom(sr.cval, other.cval))
}
// Set the Bursa-Wolf conversion to WGS84
func (sr SpatialReference) SetTOWGS84(dx, dy, dz, ex, ey, ez, ppm float64) error {
return OGRErr(C.OSRSetTOWGS84(
sr.cval,
C.double(dx),
C.double(dy),
C.double(dz),
C.double(ex),
C.double(ey),
C.double(ez),
C.double(ppm),
))
}
// Fetch the TOWGS84 parameters if available
func (sr SpatialReference) TOWGS84() (coeff [7]float64, err error) {
err = OGRErr(C.OSRGetTOWGS84(sr.cval, (*C.double)(unsafe.Pointer(&coeff[0])), 7))
return
}
// Setup a compound coordinate system
func (sr SpatialReference) SetCompoundCS(
name string,
horizontal, vertical SpatialReference,
) error {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
return OGRErr(C.OSRSetCompoundCS(sr.cval, cName, horizontal.cval, vertical.cval))
}
// Set geographic coordinate system
func (sr SpatialReference) SetGeographicCS(
geogName, datumName, spheroidName string,
semiMajor, flattening float64,
pmName string,
offset float64,
angularUnits string,
toRadians float64,
) error {
cGeogName := C.CString(geogName)
defer C.free(unsafe.Pointer(cGeogName))
cDatumName := C.CString(datumName)
defer C.free(unsafe.Pointer(cDatumName))
cSpheroidName := C.CString(spheroidName)
defer C.free(unsafe.Pointer(cSpheroidName))
cPMName := C.CString(pmName)
defer C.free(unsafe.Pointer(cPMName))
cAngularUnits := C.CString(angularUnits)
defer C.free(unsafe.Pointer(cAngularUnits))
return OGRErr(C.OSRSetGeogCS(
sr.cval,
cGeogName,
cDatumName,
cSpheroidName,
C.double(semiMajor),
C.double(flattening),
cPMName,
C.double(offset),
cAngularUnits,
C.double(toRadians),
))
}
// Set up the vertical coordinate system
func (sr SpatialReference) SetVerticalCS(csName, datumName string, datumType int) error {
cCSName := C.CString(csName)
defer C.free(unsafe.Pointer(cCSName))
cDatumName := C.CString(datumName)
defer C.free(unsafe.Pointer(cDatumName))
return OGRErr(C.OSRSetVertCS(sr.cval, cCSName, cDatumName, C.int(datumType)))
}
// Get spheroid semi-major axis
func (sr SpatialReference) SemiMajorAxis() (float64, error) {
var cErr C.OGRErr
axis := C.OSRGetSemiMajor(sr.cval, &cErr)
return float64(axis), OGRErr(cErr)
}
// Get spheroid semi-minor axis
func (sr SpatialReference) SemiMinorAxis() (float64, error) {
var cErr C.OGRErr
axis := C.OSRGetSemiMinor(sr.cval, &cErr)
return float64(axis), OGRErr(cErr)
}
// Get spheroid inverse flattening axis
func (sr SpatialReference) InverseFlattening() (float64, error) {
var cErr C.OGRErr
flat := C.OSRGetInvFlattening(sr.cval, &cErr)
return float64(flat), OGRErr(cErr)
}
// Sets the authority for a node
func (sr SpatialReference) SetAuthority(target, authority string, code int) error {
cTarget := C.CString(target)
defer C.free(unsafe.Pointer(cTarget))
cAuthority := C.CString(authority)
defer C.free(unsafe.Pointer(cAuthority))
return OGRErr(C.OSRSetAuthority(sr.cval, cTarget, cAuthority, C.int(code)))
}
// Get the authority code for a node
func (sr SpatialReference) AuthorityCode(target string) string {
cTarget := C.CString(target)
defer C.free(unsafe.Pointer(cTarget))
code := C.OSRGetAuthorityCode(sr.cval, cTarget)
return C.GoString(code)
}
// Get the authority name for a node
func (sr SpatialReference) AuthorityName(target string) string {
cTarget := C.CString(target)
defer C.free(unsafe.Pointer(cTarget))
code := C.OSRGetAuthorityName(sr.cval, cTarget)
return C.GoString(code)
}
// Set a projection by name
func (sr SpatialReference) SetProjectionByName(name string) error {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
return OGRErr(C.OSRSetProjection(sr.cval, cName))
}
// Set a projection parameter value
func (sr SpatialReference) SetProjectionParameter(name string, value float64) error {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
return OGRErr(C.OSRSetProjParm(sr.cval, cName, C.double(value)))
}
// Fetch a projection parameter value
func (sr SpatialReference) ProjectionParameter(name string, defaultValue float64) (float64, error) {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
var cErr C.OGRErr
value := C.OSRGetProjParm(sr.cval, cName, C.double(defaultValue), &cErr)
return float64(value), OGRErr(cErr)
}
// Set a projection parameter with a normalized value
func (sr SpatialReference) SetNormalizedProjectionParameter(name string, value float64) error {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
return OGRErr(C.OSRSetNormProjParm(sr.cval, cName, C.double(value)))
}
// Fetch a normalized projection parameter value
func (sr SpatialReference) NormalizedProjectionParameter(
name string, defaultValue float64,
) (float64, error) {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
var cErr C.OGRErr
value := C.OSRGetProjParm(sr.cval, cName, C.double(defaultValue), &cErr)
return float64(value), OGRErr(cErr)
}
// Set UTM projection definition
func (sr SpatialReference) SetUTM(zone int, north bool) error {
return OGRErr(C.OSRSetUTM(sr.cval, C.int(zone), BoolToCInt(north)))
}
// Get UTM zone information
func (sr SpatialReference) UTMZone() (zone int, north bool) {
var northInt C.int
cZone := C.OSRGetUTMZone(sr.cval, &northInt)
return int(cZone), northInt != 0
}
// Set State Plane projection definition
func (sr SpatialReference) SetStatePlane(zone int, nad83 bool) error {
return OGRErr(C.OSRSetStatePlane(sr.cval, C.int(zone), BoolToCInt(nad83)))
}
// Set State Plane projection definition
func (sr SpatialReference) SetStatePlaneWithUnits(
zone int,
nad83 bool,
unitName string,
factor float64,
) error {
cUnitName := C.CString(unitName)
defer C.free(unsafe.Pointer(cUnitName))
return OGRErr(C.OSRSetStatePlaneWithUnits(
sr.cval,
C.int(zone),
BoolToCInt(nad83),
cUnitName,
C.double(factor),
))
}
// Set EPSG authority info if possible
func (sr SpatialReference) AutoIdentifyEPSG() error {
return OGRErr(C.OSRAutoIdentifyEPSG(sr.cval))
}
// Return true if EPSG feels this coordinate system should be treated as having lat/long coordinate ordering
func (sr SpatialReference) EPSGTreatsAsLatLong() bool {
val := C.OSREPSGTreatsAsLatLong(sr.cval)
return val != 0
}
// Fetch the orientation of one axis
// Unimplemented: Axis
// Set to Albers Conic Equal Area
func (sr SpatialReference) SetACEA(
stdp1, stdp2, centerLat, centerLong, falseEasting, falseNorthing float64,
) error {
return OGRErr(C.OSRSetACEA(
sr.cval,
C.double(stdp1),
C.double(stdp2),
C.double(centerLat),
C.double(centerLong),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to Azimuthal Equidistant
func (sr SpatialReference) SetAE(centerLat, centerLong, falseEasting, falseNorthing float64) error {
return OGRErr(C.OSRSetAE(
sr.cval,
C.double(centerLat),
C.double(centerLong),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to Bonne
func (sr SpatialReference) SetBonne(standardParallel, centralMeridian, falseEasting, falseNorthing float64) error {
return OGRErr(C.OSRSetBonne(
sr.cval,
C.double(standardParallel),
C.double(centralMeridian),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to Cylindrical Equal Area
func (sr SpatialReference) SetCEA(stdp1, centralMeridian, falseEasting, falseNorthing float64) error {
return OGRErr(C.OSRSetCEA(
sr.cval,
C.double(stdp1),
C.double(centralMeridian),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to Cassini-Soldner
func (sr SpatialReference) SetCS(centerLat, centerLong, falseEasting, falseNorthing float64) error {
return OGRErr(C.OSRSetCS(
sr.cval,
C.double(centerLat),
C.double(centerLong),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to Equidistant Conic
func (sr SpatialReference) SetEC(
stdp1, stdp2, centerLat, centerLong, falseEasting, falseNorthing float64,
) error {
return OGRErr(C.OSRSetEC(
sr.cval,
C.double(stdp1),
C.double(stdp2),
C.double(centerLat),
C.double(centerLong),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to Eckert I-VI
func (sr SpatialReference) SetEckert(variation int, centralMeridian, falseEasting, falseNorthing float64) error {
return OGRErr(C.OSRSetEckert(
sr.cval,
C.int(variation),
C.double(centralMeridian),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to Equirectangular
func (sr SpatialReference) SetEquirectangular(
centerLat, centerLong, falseEasting, falseNorthing float64,
) error {
return OGRErr(C.OSRSetEquirectangular(
sr.cval,
C.double(centerLat),
C.double(centerLong),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to Equirectangular (generalized form)
func (sr SpatialReference) SetEquirectangularGeneralized(
centerLat, centerLong, psuedoStdParallel, falseEasting, falseNorthing float64,
) error {
return OGRErr(C.OSRSetEquirectangular2(
sr.cval,
C.double(centerLat),
C.double(centerLong),
C.double(psuedoStdParallel),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to Gall Stereographic
func (sr SpatialReference) SetGS(centralMeridian, falseEasting, falseNorthing float64) error {
return OGRErr(C.OSRSetGS(
sr.cval,
C.double(centralMeridian),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to Goode Homolosine
func (sr SpatialReference) SetGH(centralMeridian, falseEasting, falseNorthing float64) error {
return OGRErr(C.OSRSetGH(
sr.cval,
C.double(centralMeridian),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to Interrupted Goode Homolosine
func (sr SpatialReference) SetIGH() error {
return OGRErr(C.OSRSetIGH(sr.cval))
}
// Set to GEOS - Geostationary Satellite View
func (sr SpatialReference) SetGEOS(
centralMeridian, satelliteHeight, falseEasting, falseNorthing float64,
) error {
return OGRErr(C.OSRSetGEOS(
sr.cval,
C.double(centralMeridian),
C.double(satelliteHeight),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to Gauss Schreiber Transverse Mercator
func (sr SpatialReference) SetGSTM(
centerLat, centerLong, scale, falseEasting, falseNorthing float64,
) error {
return OGRErr(C.OSRSetGaussSchreiberTMercator(
sr.cval,
C.double(centerLat),
C.double(centerLong),
C.double(scale),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to gnomonic
func (sr SpatialReference) SetGnomonic(
centerLat, centerLong, falseEasting, falseNorthing float64,
) error {
return OGRErr(C.OSRSetGnomonic(
sr.cval,
C.double(centerLat),
C.double(centerLong),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to Hotine Oblique Mercator projection using azimuth angle
func (sr SpatialReference) SetHOM(
centerLat, centerLong, azimuth, rectToSkew, scale, falseEasting, falseNorthing float64,
) error {
return OGRErr(C.OSRSetHOM(
sr.cval,
C.double(centerLat),
C.double(centerLong),
C.double(azimuth),
C.double(rectToSkew),
C.double(scale),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to Hotine Oblique Mercator projection using two points on projection centerline
func (sr SpatialReference) SetHOM2PNO(
centerLat, lat1, long1, lat2, long2, scale, falseEasting, falseNorthing float64,
) error {
return OGRErr(C.OSRSetHOM2PNO(
sr.cval,
C.double(centerLat),
C.double(lat1),
C.double(long1),
C.double(lat2),
C.double(long2),
C.double(scale),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to International Map of the World Polyconic
func (sr SpatialReference) SetIWMPolyconic(
lat1, lat2, centerLong, falseEasting, falseNorthing float64,
) error {
return OGRErr(C.OSRSetIWMPolyconic(
sr.cval,
C.double(lat1),
C.double(lat2),
C.double(centerLong),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to Krovak Oblique Conic Conformal
func (sr SpatialReference) SetKrovak(
centerLat, centerLong, azimuth, psuedoStdParallel, scale, falseEasting, falseNorthing float64,
) error {
return OGRErr(C.OSRSetKrovak(
sr.cval,
C.double(centerLat),
C.double(centerLong),
C.double(azimuth),
C.double(psuedoStdParallel),
C.double(scale),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to Lambert Azimuthal Equal Area
func (sr SpatialReference) SetLAEA(
centerLat, centerLong, falseEasting, falseNorthing float64,
) error {
return OGRErr(C.OSRSetLAEA(
sr.cval,
C.double(centerLat),
C.double(centerLong),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to Lambert Conformal Conic
func (sr SpatialReference) SetLCC(
stdp1, stdp2, centerLat, centerLong, falseEasting, falseNorthing float64,
) error {
return OGRErr(C.OSRSetLCC(
sr.cval,
C.double(stdp1),
C.double(stdp2),
C.double(centerLat),
C.double(centerLong),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to Lambert Conformal Conic (1 standard parallel)
func (sr SpatialReference) SetLCC1SP(
centerLat, centerLong, scale, falseEasting, falseNorthing float64,
) error {
return OGRErr(C.OSRSetLCC1SP(
sr.cval,
C.double(centerLat),
C.double(centerLong),
C.double(scale),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to Lambert Conformal Conic (Belgium)
func (sr SpatialReference) SetLCCB(
stdp1, stdp2, centerLat, centerLong, falseEasting, falseNorthing float64,
) error {
return OGRErr(C.OSRSetLCCB(
sr.cval,
C.double(stdp1),
C.double(stdp2),
C.double(centerLat),
C.double(centerLong),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to Miller Cylindrical
func (sr SpatialReference) SetMC(
centerLat, centerLong, falseEasting, falseNorthing float64,
) error {
return OGRErr(C.OSRSetMC(
sr.cval,
C.double(centerLat),
C.double(centerLong),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to Mercator
func (sr SpatialReference) SetMercator(
centerLat, centerLong, scale, falseEasting, falseNorthing float64,
) error {
return OGRErr(C.OSRSetMercator(
sr.cval,
C.double(centerLat),
C.double(centerLong),
C.double(scale),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set tp Mollweide
func (sr SpatialReference) SetMollweide(
centralMeridian, falseEasting, falseNorthing float64,
) error {
return OGRErr(C.OSRSetMollweide(
sr.cval,
C.double(centralMeridian),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to New Zealand Map Grid
func (sr SpatialReference) SetNZMG(
centerLat, centerLong, falseEasting, falseNorthing float64,
) error {
return OGRErr(C.OSRSetNZMG(
sr.cval,
C.double(centerLat),
C.double(centerLong),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to Oblique Stereographic
func (sr SpatialReference) SetOS(
originLat, meridian, scale, falseEasting, falseNorthing float64,
) error {
return OGRErr(C.OSRSetOS(
sr.cval,
C.double(originLat),
C.double(meridian),
C.double(scale),
C.double(falseEasting),
C.double(falseNorthing),
))
}
// Set to Orthographic
func (sr SpatialReference) SetOrthographic(
centerLat, centerLong, falseEasting, falseNorthing float64,
) error {
return OGRErr(C.OSRSetOrthographic(