Skip to content

Commit

Permalink
更新文档:转换工具增加文件格式批量互转功能,SHP、JSON、KML、KMZ、GML、GPKG 等互转
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangyuecn committed Jul 9, 2023
1 parent 55a7fd1 commit def5df2
Show file tree
Hide file tree
Showing 6 changed files with 599 additions and 22 deletions.
Binary file added assets/AGT-Images/sy-9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 105 additions & 0 deletions assets/AGT/WebviewSettings.html
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@
<option value=""></option>
<option value="">==== 工具集 ====</option>
<option value="custom_sql_config">[插件] 通用自定义SQL配置(任意数据库适配)</option>
<option value="vector_file_format_convert">[转换] 文件格式批量互转 SHP|JSON|KML|GML|……</option>
<option value="geojson_level_split">[拆分] GeoJSON 按省市区将下级拆分到多个文件</option>
<option value="geojson_merge">[合并] GeoJSON 多个文件合并成一个文件</option>

Expand Down Expand Up @@ -442,6 +443,7 @@
window.onerror=function(message, url, lineNo, columnNo, error){
//https://www.cnblogs.com/xianyulaodi/p/6201829.html
Runtime.Log('<span style="color:red">【Uncaught Error】'+message+'<pre>'+"at:"+lineNo+":"+columnNo+" url:"+url+"\n"+(error&&error.stack||"不能获得错误堆栈")+'</pre></span>',1);
AppCmds.showTips('【脚本错误】'+message+'\r\nat:'+lineNo+":"+columnNo+" url:"+url+"\r\n"+(error&&error.stack||"不能获得错误堆栈").replace(/\r?\n/g,"\r\n"),true);
};
})();
</script>
Expand Down Expand Up @@ -693,6 +695,109 @@



<script>
function RandomKey(len){
var s=[];
for(var i=0;i<len;i++){
s.push(String.fromCharCode(Math.floor(Math.random()*26)+97));
};
return s.join("");
};
function ParseObject(str){
var val,err;
if(str && typeof(str)=="string"){
try{
val=JSON.parse(str);
}catch(e){
err=e;
};
};
ParseObject.e=err;
return val||{};
};
function ParseArray(str){
var val,err;
if(str && typeof(str)=="string"){
try{
val=JSON.parse(str);
}catch(e){
err=e;
};
};
ParseArray.e=err;
return val||[];
};

function FormatDate(date,type,sp){
if(typeof(type)=="string"){
type=FormatDate[type];
}
if(sp==null){
sp="-";
}
date=date==null?new Date():ParseDateObject(date)||new Date(Date1800);
var Y=date.getFullYear()
,mM=date.getMonth()+1
,M=("0"+mM).slice(-2)
,mD=date.getDate()
,D=("0"+mD).slice(-2)
,th=date.getHours()
,h=("0"+th).slice(-2)
,tm=date.getMinutes()
,m=("0"+tm).slice(-2)
,ts=date.getSeconds()
,s=("0"+ts).slice(-2)
,tS=date.getMilliseconds()
,S=("00"+tS).slice(-3)
,o=FormatDate;
switch(type){
case o.YMD:return Y+sp+M+sp+D;
case o.HM:return h+":"+m;
case o.YMDHMS:return Y+sp+M+sp+D+" "+h+":"+m+":"+s;
case o.YMDHM:return Y+sp+M+sp+D+" "+h+":"+m;
case o.NUM:return date.getTime();
default:return Y+sp+M+sp+D+" "+h+":"+m+":"+s+"."+S;
}
}
FormatDate.YMD=1;
FormatDate.HM=5;
FormatDate.YMDHMS=6;
FormatDate.YMDHM=7;
FormatDate.NUM=9;
FormatDate.DEF=0;

var Date1800=new Date(1800,6-1,1).getTime();
function ParseDateObject(date){
if(typeof(date)=="number"){
return new Date(date);
}
if(!date){
return null;
}
if(!date.getFullYear){
if(/^(\d{4})[^\d]*(\d\d?)[^\d]*(\d\d?)[^\d]*(?:(\d\d?)[^\d]*(\d\d?)[^\d]*(?:(\d\d?)[^\d]*(\d{1,3})?)?)?$/.test(date+"")){//xx xx:12.456 火狐 IE更加不支持
date=new Date(
+RegExp.$1
,+RegExp.$2-1
,+RegExp.$3

,+RegExp.$4||0
,+RegExp.$5||0
,+RegExp.$6||0
,+RegExp.$7||0
);
}else{
date=new Date(date+"");
}
}
try{
return date&&date.getFullYear()?date:null;
}catch(e){
return null;
}
}
</script>

<script>
(function(){

Expand Down
21 changes: 12 additions & 9 deletions assets/AGT/WebviewSettingsCodes/custom_sql_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ window.setTempl=function(type,isInit){
createV.push("通用WKT纯文本格式,绝大部分数据库都支持导入此SQL文件,包括SQLite");
}else if(type==2){
createV.push("Oracle数据库格式,请在Oracle中导入此SQL文件");
createV.push(" - 注意:Oracle的SDO_GEOMETRY必须提供一个SRID,不然会导致空间计算不准确甚至无法调用(包括SRID=0时),当前导出数据的SRID=4326(WGS84);Oracle不支持任何EMPTY,只能用NULL代替");
createV.push(" - 查询一个坐标对应的城市SQL语句示例:");
createV.push(" select ${Field_ID},${Field_ExtPath},SDO_GEOMETRY.GET_WKT(polygon) as polygon from ${TableName} where SDO_ANYINTERACT(polygon,SDO_GEOMETRY('POINT (114.044346 22.691963)',4326))='TRUE';");
}else if(type==3){
createV.push("ST_GeomFromText兼容格式,适用于支持ST_GeomFromText函数的数据库,比如MySQL8+、PostgreSQL");
}else if(type==4){
Expand All @@ -119,6 +122,7 @@ window.setTempl=function(type,isInit){
createV.push(" select count(1) into num from user_tables where table_name = upper('${TableName}');");
createV.push(" if num > 0 then execute immediate 'drop table ${TableName}'; end if;");
createV.push('end;');
createV.push('/');
}else if(type==4){
//NOOP
}else{ return fail(); }
Expand All @@ -130,8 +134,8 @@ window.setTempl=function(type,isInit){
createV.push(' ${Field_Geo} text NOT NULL, //@ text为长文本类型,应当使用此数据库支持的最长的类型,比如mysql为longtext');
createV.push(' ${Field_Polygon} text NOT NULL');
}else if(type==2){
createV.push(' ${Field_Geo} SDO_GEOMETRY NOT NULL,');
createV.push(' ${Field_Polygon} SDO_GEOMETRY NOT NULL');
createV.push(' ${Field_Geo} SDO_GEOMETRY NULL,');
createV.push(' ${Field_Polygon} SDO_GEOMETRY NULL');
}else if(type==3){
createV.push(' ${Field_Geo} geometry NOT NULL,');
createV.push(' ${Field_Polygon} geometry NOT NULL');
Expand All @@ -150,8 +154,8 @@ window.setTempl=function(type,isInit){
insertV.push("'${Value_Geo|POINT EMPTY}',");
insertV.push("'${Value_Polygon|POLYGON EMPTY}'");
}else if(type==2){
insertV.push("SDO_GEOMETRY('${Value_Geo|POINT EMPTY}',0),");
insertV.push("SDO_GEOMETRY('${Value_Polygon|POLYGON EMPTY}',0)");
insertV.push("${Value_Geo|SDO_GEOMETRY('?',4326)|NULL},");
insertV.push("${Value_Polygon|SDO_GEOMETRY('?',4326)|NULL}");
}else if(type==3){
insertV.push("ST_GeomFromText('${Value_Geo|POINT EMPTY}',0),");
insertV.push("ST_GeomFromText('${Value_Polygon|POLYGON EMPTY}',0)");
Expand All @@ -160,8 +164,6 @@ window.setTempl=function(type,isInit){
}else{ return fail(); }
insertV.push(");");
insertV.push("\n\n//@ 这些字段值的顺序必须和创建表的字段顺序一致");
insertV.push("\n//@ OtherValues变量为:csv内更多要导出的非预定义字段值,数字和字符串两种类型,后面两个参数为对应字段的值格式,?为值的占位符");
insertV.push("\n//@ Value_Geo和Value_Polygon后面的参数为图形为空时的WKT字符串,比如mysql只有GEOMETRYCOLLECTION EMPTY");

//csv格式单独重新弄一份
if(type==4){
Expand All @@ -178,10 +180,11 @@ window.setTempl=function(type,isInit){

insertV.push('${Value_ID},${OtherValues|?|"?"},"${Value_ExtPath}","${Value_Geo|POINT EMPTY}","${Value_Polygon|POLYGON EMPTY}"');
insertV.push("\n\n//@ 这些字段值的顺序必须和表头的字段顺序一致");
insertV.push("\n//@ OtherValues变量为:更多要导出的非预定义字段值,数字和字符串两种类型,后面两个参数为对应字段的值格式,?为值的占位符");
insertV.push("\n//@ Value_Geo和Value_Polygon后面的参数为图形为空时的WKT字符串");
}

insertV.push("\n//@ OtherValues变量为:更多要导出的非预定义字段值,数字和字符串两种类型,后面两个参数为对应字段的值格式,?为值的占位符");
insertV.push("\n//@ Value_Geo和Value_Polygon后面接一个参数时为图形为空时的WKT字符串,比如mysql只有GEOMETRYCOLLECTION EMPTY;接两个参数时为有值的格式和为空的格式,?为WKT字符串占位符");



var tableEl=$(".csc_in_tableSQL")[0]._edit,insertEl=$(".csc_in_insertSQL")[0]._edit;
Expand All @@ -197,7 +200,7 @@ setTempl(1,1);

//完成配置
window.runClick=function(){
if(Runtime.VersionLess("1.3.230403")){
if(Runtime.VersionLess("1.3.230709")){
var tips="软件版本过低,请重新下载升级后再操作";
AppCmds.showTips(tips,true);Runtime.Log(tips,1);
return;
Expand Down
Loading

0 comments on commit def5df2

Please sign in to comment.