-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
127 lines (108 loc) · 4.2 KB
/
cli.js
File metadata and controls
127 lines (108 loc) · 4.2 KB
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
const geotoolsFactory = require("./index");
const _ = require('lodash');
require('yargs')
.command({
command: 'getNames <dataStoreUrl>',
desc: 'Get the names of all entries or types provided by the datastore',
builder: (yargs) => {
yargs
.positional('dataStoreUrl',{
describe: 'The URL for the data store',
type: 'string'
}
)
.options({
'c': {
alias: 'className',
//default: 'org.geotools.data.shapefile.ShapefileDataStoreFactory',
default: 'org.geotools.data.vpf.VPFDataStoreFactory',
describe: 'Concreate Java class name for the ContentDataStore instance',
type: 'string'
},
'd': {
alias: 'dataStoreTypeName',
//default: 'SHAPEFILE',
//default: 'VPF',
default: null,
describe: 'Type name of data store',
type: 'string'
},
})
},
handler: async (argv) => {
const geotools = await geotoolsFactory.getInstance();
const className = !_.isNil(argv.dataStoreTypeName) ?
geotools.getDataStoreClass(argv.dataStoreTypeName) : argv.className;
const factory = geotools.createDataStoreFactoryFromClass(className);
var libName = factory.getDisplayName();
const params = geotools.fileToUrlParams(argv.dataStoreUrl);
const store = factory.createDataStore(params);
const names = store.getTypeNames();
const json = {
"dataStoreUrl": argv.dataStoreUrl,
"className": className,
"libraryType": libName,
"names": names
};
console.log(JSON.stringify(json,null,2));
}
})
.command({
command: 'getFeatures <dataStoreUrl> <typeName>',
desc: 'Get the features with typeName from the datastore',
builder: (yargs) => {
yargs
.positional('dataStoreUrl',{
describe: 'The URL for the data store',
type: 'string'
}
)
.options({
'c': {
alias: 'className',
default: 'org.geotools.data.shapefile.ShapefileDataStoreFactory',
//default: 'org.geotools.data.vpf.VPFDataStoreFactory',
describe: 'Concreate Java class name for the ContentDataStore instance',
type: 'string'
},
'd': {
alias: 'dataStoreTypeName',
//default: 'SHAPEFILE',
//default: 'VPF',
default: null,
describe: 'Type name of data store',
type: 'string'
},
})
},
handler: async (argv) => {
try {
const geotools = await geotoolsFactory.getInstance();
const className = !_.isNil(argv.dataStoreTypeName) ?
geotools.getDataStoreClass(argv.dataStoreTypeName) : argv.className;
const factory = geotools.createDataStoreFactoryFromClass(className);
var libName = factory.getDisplayName();
const params = geotools.fileToUrlParams(argv.dataStoreUrl);
const store = factory.createDataStore(params);
const fs = store.getFeatureSource(argv.typeName);
/*
const featureType = fs.getSchema();
const features = geotools.createListFeatureCollection(featureType);
const rdr = fs.getReader();
while(rdr.hasNext()) {
const feature = rdr.next();
//console.log(fjson.toString(feature));
features.add(feature);
}
*/
const features = fs.getFeatures();
const fjson = geotools.createFeatureJSON();
console.log(fjson.toString(features));
}
catch(e) {
console.log(e);
}
}
})
.help()
.argv