-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_gcp_convert_upload.asv
49 lines (40 loc) · 1.87 KB
/
test_gcp_convert_upload.asv
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
start_dir = 'D:\Local\mapwarper-tools';
cd(start_dir);
mw_mapnum = 793; % The mapwarper item number
% Gather secrets:
secrets = struct;
secrets.username = input('Enter mapwarper username (email): ','s');
secrets.password = input('Enter mapwarper password: ','s');
%%% Load the QGIS gcp file:
[H, C] = read_mapwarper_list([start_dir '/gcp-tests/gcp-' num2str(mw_mapnum) '.csv'],',',1);
%%% Convert C from a cell array to a matrix
C2 = cellfun(@str2double,C);
%%% Rearrange order and convert to MapWarper-compliant format
% mapX,mapY,sourceX,sourceY(QGIS) --> x,y,lon,lat (MW); y has opposite sign
% to sourceY
% C_out = [C2(:,3) -1.*C2(:,4) C2(:,1) C2(:,2)];
% gcps.mapid = repmat(mw_mapnum,size(C2,1),1);
% gcps.x = C2(:,3);
% gcps.y = -1.*C2(:,4);
% gcps.lon = C(:,1);
% gcps.lat = C(:,2);
% json_out = jsonencode(gcps)
%%% Let's just try to write the json snippet
% e.g., {"gcps":[{"mapid":123,"x":2,"y":3,"lat":"52.56","lon":"-4.65"},{"mapid":123,"x":12,"y":23,"lat":"32.56","lon":"-2.65"}]}
json_out = '{"gcps":[';
for i = 1:1:size(C2,1)
json_out = [json_out '{"mapid":' num2str(mw_mapnum) ',"x":' num2str(C2(i,3)) ',"y":' num2str(-1.*C2(i,4)) ',"lat":"' C{i,2} '","lon":"' C{i,1} '"},'];
end
json_out = [json_out(1:end-1) ']}']; %Remove final trailing comma
% Build the full API string:
to_execute = ['curl-7.69.1-win64-mingw\bin\curl -H "Content-Type: application/json" -H "Accept: application/json" '...
'-X POST -u ' secrets.username ':' secrets.password ' -d ''' json_out ''' https://mapexplorer.lib.mcmaster.ca/api/v1/gcps/add_many -b cookie'];
results(i).execute = to_execute;
% Run the command:
[results(i).status,results(i).cmdout] = dos(to_execute);
switch results(i).status
case 0
disp(['GCP list for Map ' num2str(mw_mapnum) ' processed. /n API Response: ' results(i).cmdout]);
case 1
disp(['GCP list for Map ' num2str(mw_mapnum) ' - upload failed']);
end