本节将概述从 WKT 文件装载空间数据的过程。
首先按如下方式创建一个包含空间数据的 WKT 文件,以便稍后将其装载到数据库中:
打开一个文本编辑器,如记事本。
以下代码片段中包含一组以 WKT 格式定义的几何。将该片段的内容复制粘贴到文本编辑器中:
head,"CircularString(1.1 1.9, 1.1 2.5, 1.1 1.9)" left iris,"Point(0.96 2.32)" right iris,"Point(1.24 2.32)" left eye,"MultiCurve(CircularString(0.9 2.32, 0.95 2.3, 1.0 2.32),CircularString(0.9 2.32, 0.95 2.34, 1.0 2.32))" right eye,"MultiCurve(CircularString(1.2 2.32, 1.25 2.3, 1.3 2.32),CircularString(1.2 2.32, 1.25 2.34, 1.3 2.32))" nose,"CircularString(1.1 2.16, 1.1 2.24, 1.1 2.16)" mouth,"CircularString(0.9 2.10, 1.1 2.00, 1.3 2.10)" hair,"MultiCurve(CircularString(1.1 2.5, 1.0 2.48, 0.8 2.4),CircularString(1.1 2.5, 1.0 2.52, 0.7 2.5),CircularString(1.1 2.5, 1.0 2.56, 0.9 2.6),CircularString(1.1 2.5, 1.05 2.57, 1.0 2.6))" neck,"LineString(1.1 1.9, 1.1 1.8)" clothes and box,"MultiSurface(((1.6 1.9, 1.9 1.9, 1.9 2.2, 1.6 2.2, 1.6 1.9)),((1.1 1.8, 0.7 1.2, 1.5 1.2, 1.1 1.8)))" L,"MultiCurve(CircularString(1.05 1.56, 1.03 1.53, 1.05 1.50),CircularString(1.05 1.50, 1.10 1.48, 1.15 1.52),CircularString(1.15 1.52, 1.14 1.54, 1.12 1.53),CircularString(1.12 1.53, 1.06 1.42, 0.95 1.28),CircularString(0.95 1.28, 0.92 1.31, 0.95 1.34),CircularString(0.95 1.34, 1.06 1.28, 1.17 1.32))" holes in box,"MultiPoint((1.65 1.95),(1.75 1.95),(1.85 1.95),(1.65 2.05),(1.75 2.05),(1.85 2.05),(1.65 2.15),(1.75 2.15),(1.85 2.15))" arms and legs,"MultiLineString((0.9 1.2, 0.9 0.8),(1.3 1.2, 1.3 0.8),(0.97 1.6, 1.6 1.9),(1.23 1.6, 1.7 1.9))" left cart wheel,"CircularString(2.05 0.8, 2.05 0.9, 2.05 0.8)" right cart wheel,"CircularString(2.95 0.8, 2.95 0.9, 2.95 0.8)" cart body,"Polygon((1.9 0.9, 1.9 1.0, 3.1 1.0, 3.1 0.9, 1.9 0.9))" angular shapes on cart,"MultiPolygon(((2.18 1.0, 2.1 1.2, 2.3 1.4, 2.5 1.2, 2.35 1.0, 2.18 1.0)),((2.3 1.4, 2.57 1.6, 2.7 1.3, 2.3 1.4)))" round shape on cart,"CurvePolygon(CompoundCurve(CircularString(2.6 1.0, 2.7 1.3, 2.8 1.0),(2.8 1.0, 2.6 1.0)))" cart handle,"GeometryCollection(MultiCurve((2.0 1.0, 2.1 1.0),CircularString(2.0 1.0, 1.98 1.1, 1.9 1.2),CircularString(2.1 1.0, 2.08 1.1, 2.0 1.2),(1.9 1.2, 1.85 1.3),(2.0 1.2, 1.9 1.35),(1.85 1.3, 1.9 1.35)),CircularString(1.85 1.3, 1.835 1.29, 1.825 1.315),CircularString(1.9 1.35, 1.895 1.38, 1.88 1.365),LineString(1.825 1.315, 1.88 1.365))" |
将文件另存为 wktgeometries.csv。
在 Interactive SQL 中,以 DBA 用户身份或 SYS_SPATIAL_ADMIN_ROLE 组成员身份连接到示例数据库 (demo.db)。
创建一个名为 SA_WKT 的表,然后按如下方式将数据从 wktgeometries.csv 装载到该表中。确保将 .csv 文件的路径替换为该文件的保存路径:
DROP TABLE IF EXISTS SA_WKT; CREATE TABLE SA_WKT ( description CHAR(24), sample_geometry ST_Geometry(SRID=1000004326) ); LOAD TABLE SA_WKT FROM 'C:\\Documents and Settings\\All Users\\Documents\\SQL Anywhere 12\\Samples\\wktgeometries.csv' DELIMITED BY ','; |
这些数据即被装载到表中。
在 Interactive SQL 中,选择 [工具] » [空间查看器]。
在 [空间查看器] 中,执行以下命令以查看几何:
SELECT * FROM SA_WKT; |
您的数据中所包含的空间数据列可能不止一个。在接下来的示例中,您将创建一个 WKT 数据文件,文件包含分别存储在单独的列中的受支持空间数据类型。
将以下代码片段复制到文本编辑器中,然后将文件另存为 wktgeometries2.csv:
"Point(0 0)",,,,,,,,,,,,,, ,"LineString(0 0, 1 1)",,,,,,,,,,,,, ,,"CircularString(0 0, 1 1, 0 0)",,,,,,,,,,,, ,,,"CompoundCurve(CircularString(0 0, 1 1, 1 0),(1 0, 0 1))",,,,,,,,,,, ,,,,"CompoundCurve(CircularString(0 0, 1 1, 1 0),(1 0, 0 1),(0 1, 0 0))",,,,,,,,,, ,,,,,"Polygon((-1 0, 1 0, 2 1, 0 3, -2 1, -1 0))",,,,,,,,, ,,,,,,"CurvePolygon(CompoundCurve(CircularString(0 0, 1 1, 1 0),(1 0, 0 0)))",,,,,,,, ,,,,,,,"CurvePolygon(CompoundCurve(CircularString(0 0, 2 1, 2 0),(2 0, 0 0)))",,,,,,, ,,,,,,,,"MultiPoint((2 0),(0 0),(3 0),(1 0))",,,,,, ,,,,,,,,,"MultiPolygon(((4 0, 4 1, 5 1, 5 0, 4 0)),((-1 0, 1 0, 2 1, 0 3, -2 1, -1 0)))",,,,, ,,,,,,,,,,"MultiSurface(((4 0, 4 1, 5 1, 5 0, 4 0)),CurvePolygon(CompoundCurve(CircularString(0 0, 2 1, 2 0),(2 0, 0 0))))",,,, ,,,,,,,,,,,"MultiLineString((2 0, 0 0),(3 0, 1 0),(-2 1, 0 4))",,, ,,,,,,,,,,,,"MultiCurve((3 2, 4 3),CircularString(0 0, 1 1, 0 0))",, ,,,,,,,,,,,,,"GeometryCollection(MultiPoint((2 0),(0 0),(3 0),(1 0)),MultiSurface(((4 0, 4 1, 5 1, 5 0, 4 0)),CurvePolygon(CompoundCurve(CircularString(0 0, 2 1, 2 0),(2 0, 0 0)))),MultiCurve((3 2, 4 3),CircularString(0 0, 1 1, 0 0)))", ,,,,,,,,,,,,,,"GeometryCollection(Point(0 0),CompoundCurve(CircularString(0 0, 1 1, 1 0),(1 0, 0 1),(0 1, 0 0)),CurvePolygon(CompoundCurve(CircularString(0 0, 2 1, 2 0),(2 0, 0 0))),MultiPoint((2 0),(0 0),(3 0),(1 0)),MultiSurface(((4 0, 4 1, 5 1, 5 0, 4 0)),CurvePolygon(CompoundCurve(CircularString(0 0, 2 1, 2 0),(2 0, 0 0)))),MultiCurve((3 2, 4 3),CircularString(0 0, 1 1, 0 0)))" |
创建一个名为 SA_WKT2 的表,然后按如下方式将数据从 wktgeometries2.csv 装载到该表中。确保将 csv 文件的路径替换为 wktgeometries2.csv 文件的保存路径:
DROP TABLE IF EXISTS SA_WKT2; CREATE TABLE SA_WKT2 ( point ST_Point, line ST_LineString, circle ST_CircularString, compoundcurve ST_CompoundCurve, curve ST_Curve, polygon1 ST_Polygon, curvepolygon ST_CurvePolygon, surface ST_Surface, multipoint ST_MultiPoint, multipolygon ST_MultiPolygon, multisurface ST_MultiSurface, multiline ST_MultiLineString, multicurve ST_MultiCurve, geomcollection ST_GeomCollection, geometry ST_Geometry ); LOAD TABLE SA_WKT2 FROM 'C:\\Documents and Settings\\All Users\\Documents\\SQL Anywhere 12\\Samples\\wktgeometries2.csv' DELIMITED BY ','; |
这些数据即被装载到表中。
在 [空间查看器] 中,执行以下命令以查看几何。
请注意,一次只能查看一个数据列;要查看其它列的几何,必须使用 [结果] 区中的 [列] 下拉菜单。例如,以下显示的就是 curvepolygon 列中的几何:
要同时查看所有列中的几何,可先针对各列执行 SELECT 语句,然后再对所有结果执行 UNION ALL 命令,具体方式如下:
SELECT point FROM SA_WKT2 UNION ALL SELECT line FROM SA_WKT2 UNION ALL SELECT circle FROM SA_WKT2 UNION ALL SELECT compoundcurve FROM SA_WKT2 UNION ALL SELECT curve FROM SA_WKT2 UNION ALL SELECT polygon1 FROM SA_WKT2 UNION ALL SELECT curvepolygon FROM SA_WKT2 UNION ALL SELECT surface FROM SA_WKT2 UNION ALL SELECT multipoint FROM SA_WKT2 UNION ALL SELECT multipolygon FROM SA_WKT2 UNION ALL SELECT multisurface FROM SA_WKT2 UNION ALL SELECT multiline FROM SA_WKT2 UNION ALL SELECT multicurve FROM SA_WKT2 UNION ALL SELECT geomcollection FROM SA_WKT2 UNION ALL SELECT geometry FROM SA_WKT2 |
![]() |
使用DocCommentXchange 讨论此页。
|
版权 © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |