当前位置: 代码迷 >> GIS >> Oracle function real_st_astext,解决ArcSDE中st_astext函数返回字符串结构错误有关问题
  详细解决方案

Oracle function real_st_astext,解决ArcSDE中st_astext函数返回字符串结构错误有关问题

热度:667   发布时间:2016-05-05 06:02:56.0
Oracle function real_st_astext,解决ArcSDE中st_astext函数返回字符串结构异常问题

项目过程中发现在Oracle中调用ArcSDE的st_astext函数返回ST_Geometry类型字段的WKT文本有时空间类型前缀没有返回,例如一个点的经度为113.4,纬度为30.6,调用st_astext函数正常返回就应该是“POINT(113.4 30.6)”,但有时返回的是“(113.4 30.6)”,缺少POINT前缀,以下real_st_astext函数可解决该问题。

create or replace function real_st_astext(geom1 in clob) return clob is  geometry clob;  tempGeom clob;  geom clob;  lonlatStr clob;--第一段经纬度字符串  firstStr clob;--第一个点的经纬度  lastIndex int;--第一个点最后一次出现的游标begin  geom := trim(geom1);  geom := replace(geom,'( ','(');  geom := replace(geom,' (','(');  geom := replace(geom,') ',')');  geom := replace(geom,' )',')');  geom := replace(geom,', ',',');  geometry := upper(geom);  if geom like '(((%' then    geometry := 'MULTIPOLYGON' || geom;  else    if geom like '((%' then      tempGeom := substr(geom, instr(geom, '((') + 2, length(geom));      lonlatStr := substr(tempGeom, 0, instr(tempGeom, ')')-1);      firstStr := trim(substr(lonlatStr, 0, instr(lonlatStr, ',')-1));      lastIndex := instr(lonlatStr, firstStr, -1);      if lastIndex = length(lonlatStr) - length(firstStr) + 1 then        geometry := 'POLYGON '||geom;      else        geometry := 'MULTILINESTRING ' || geom;      end if;    else      if geom like '(%' then        if geom like '%,%' then          geometry := 'LINESTRING' || geom;        else          geometry := 'POINT' || geom;        end if;      end if;    end if;  end if;  return geometry;end;
  相关解决方案