R上的交互式缩放地图

时间:2015-11-18 16:20:50

标签: maps zoom

所以我正在做一个项目,我希望用县创建一张美国地图。我目前已成功创建了一个地图,但我正在寻求改进它。我有兴趣生成一个地图,其中它将向美国显示状态,如果我点击状态,它将放大并显示列出的县的状态。然后我希望能够点击县以获取R中数据集中的相应信息。这可以在R中执行,如果是这样,任何帮助都将非常感激。

这是我目前使用的代码:

library(devtools)
find_rtools()
devtools::install_github("hafen/housingData")
library(housingData);library(devtools)

head(geoCounty)
geo <- divide(geoCounty, by = c("state", "county"))
geo[[1]]

install.packages(maps)
install.packages(maptools)
library(maps)
library(maptools)

US <- map("state",fill=TRUE, plot=FALSE)
US.names <- US$names
US.IDs <- sapply(strsplit(US.names,":"),function(x) x[1])
US_poly_sp <- map2SpatialPolygons(US,IDs=US.IDs,proj4string=CRS("+proj=longlat 
+ datum=wgs84"))
plot(US_poly_sp,col="white",axes=TRUE)
points(geoCounty$lon, geoCounty$lat)

谢谢, 乔伊

1 个答案:

答案 0 :(得分:2)

乔伊, 怎么样?

ThriftMemoryBuffer* tbuffer = g_object_new(THRIFT_TYPE_MEMORY_BUFFER,
    "buf_size", 2048, NULL);
ThriftTransport *transport = NULL;
ThriftProtocol* protocol = NULL;
GError* error = NULL;

if (tbuffer) {
    transport = THRIFT_TRANSPORT(tbuffer);
    thrift_transport_open(transport, &error);

    protocol =
    THRIFT_PROTOCOL(
        g_object_new(THRIFT_TYPE_BINARY_PROTOCOL, "transport", transport, NULL));

    if (protocol) {
        ExceptionData* exception_data = g_object_new(TYPE_EXCEPTION_DATA, "ex_sign",
            exception_signature, "cl_sign", class_signature, "caught",
            catch_method != NULL,
            NULL);

        if (exception_data) {
            ThriftStructClass* cls = THRIFT_STRUCT_CLASS(EXCEPTION_DATA_GET_CLASS(exception_data));
            cls->write(exception_data, protocol, &error);

            if(tbuffer->buf != NULL) {

                printf("Buffer length %i bytes\n", tbuffer->buf->len);

                send_kafka_message((const void *)tbuffer->buf->data, tbuffer->buf->len);
            }

            g_object_unref(exception_data);
        }

        g_object_unref(protocol);
    }

    if (thrift_transport_is_open(transport)) {
        thrift_transport_close(transport, &error);
    }

    g_object_unref(tbuffer);
}
最佳