You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

新西兰地址转NZTM遇400错误,求Python实现及请求修正方案

新西兰地址转NZTM坐标的问题与请求

需求

编写Python脚本,将单条新西兰街道地址(如“28 Stanley Street, Parnell”)转换为NZTM(新西兰横轴墨卡托投影)格式的精确坐标。

疑问

  • 使用带cql_filter的WFS服务进行单地址查询是否为当前标准方法?
  • 是否存在更简便的RESTful地理编码API?

尝试过的服务

  • Auckland Council APIs:链接失效、服务器超时,ArcGIS REST端点已停用;
  • NZ Post AddressChecker API:需新西兰邮政商业账户,无法使用;
  • LINZ Data Service(LDS):已注册免费账户并获取API Key,但请求被拒绝。

当前问题

调用LDS官方“NZ Addresses”数据集(layer-105688)的WFS端点时,持续返回400 Bad Request错误。

使用的Python代码

import requests

# My LDS API Key
api_key = "PASTE_YOUR_KEY_HERE"

# The address components I'm trying to find
address_number = 28
road_name = "STANLEY STREET"
suburb = "PARNELL"

# The LINZ WFS endpoint and the NZ Addresses layer ID
layer_id = "105688"
base_url = f"https://data.linz.govt.nz/services;key={api_key}/wfs"

# Building a structured query to find the address
cql_filter_query = (
    f"address_number={address_number} AND "
    f"full_road_name='{road_name}' AND "
    f"suburb_locality='{suburb}'"
)

# Setting up the request parameters
params = {
    'service': 'WFS',
    'version': '2.0.0',
    'request': 'GetFeature',
    'typeNames': f'layer-{layer_id}',
    'outputFormat': 'application/json',
    'srsName': 'EPSG:2193',          # Asking for NZTM coordinates
    'cql_filter': cql_filter_query
}

# Making the request
try:
    response = requests.get(base_url, params=params)
    response.raise_for_status()
    print(response.json())
except requests.exceptions.RequestException as e:
    print(f"An error occurred: {e}")
    if 'response' in locals() and response:
        print(f"Error details: {response.text}")

错误信息

An error occurred: 400 Client Error: Bad Request for url: https://data.linz.govt.nz/services;key=.../wfs?service=WFS&version=2.0.0&request=GetFeature&typeNames=layer-105688&outputFormat=application%2Fjson&srsName=EPSG%3A2193&cql_filter=address_number%3D28+AND+full_road_name%3D%27STANLEY+STREET%27+AND+suburb_locality%3D%27PARNELL%27

请求

如何调整请求格式以满足要求?


内容的提问来源于stack exchange,提问作者Cherish Roby

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 16:57:36