【发布时间】:2018-06-12 08:59:44
【问题描述】:
我正在尝试创建一个架构来验证 GeoJSON 正在加载的文件:
validSchema = StructType([
StructField("type", StringType()),
StructField("geometry", StructType([
StructField("coordinates", ArrayType(DoubleType())), # POINT
StructField("coordinates", ArrayType(ArrayType(ArrayType(DoubleType())))), # POLYGON
StructField("coordinates", ArrayType(ArrayType(DoubleType()))), # LINESTRING
StructField("type", StringType(), False)
]), False),
StructField("properties", MapType(StringType(), StringType()))
])
df = spark.read.option("multiline","true").json(src_data,mode="PERMISSIVE",schema=validSchema)
问题是我有三种“坐标”来满足有效的 GeoJSON 类型。但是,只有最后一条规则有效,我假设它根据顺序优先于前两条。
有没有将模式指定为坐标模式之一必须匹配?
现在我能看到的唯一方法是创建三个模式和三个导入,这意味着扫描所有数据三次(我有 5TB 的数据,所以这看起来很疯狂)。
geoJSON 数据示例:
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [[[ -0.144195556640625,52.019120643633386],
[-0.127716064453125,52.00052411347729],
[-0.10848999023437499,52.01193653675363],
[-0.12359619140625,52.02883848153626],
[-0.144195556640625,52.019120643633386]]]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [[-0.196380615234375,52.11283076186275],
[-0.1263427734375,52.07739600418385]]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-0.1641082763671875, 52.06051241654061]
}
}
谢谢
【问题讨论】:
标签: json apache-spark pyspark geojson