{"__v":29,"_id":"54fdffc25de33c2d0031127a","category":{"__v":12,"_id":"54fdff31f7b1202100a25e06","pages":["54fdff6bf7b1202100a25e07","54fdff85f7b1202100a25e09","54fdffa1f7b1202100a25e0b","54fdffc25de33c2d0031127a","54fdffe5f7b1202100a25e0e","550199dc0459bd3700770d87","5501d14df2ef1e0d003116ba","5501d1e70459bd3700770e1c","5501d1f4f2ef1e0d003116bd","5501d20f0459bd3700770e1e","5501d2220459bd3700770e20","5501ecbaf2ef1e0d0031171d"],"project":"54d0fd1d095c470d00d1646d","version":"54d0fd1e095c470d00d16470","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-03-09T20:14:41.719Z","from_sync":false,"order":1,"slug":"tutorials","title":"Tutorials"},"project":"54d0fd1d095c470d00d1646d","user":"54db5301eb78f13900cf108b","version":{"__v":20,"_id":"54d0fd1e095c470d00d16470","project":"54d0fd1d095c470d00d1646d","createdAt":"2015-02-03T16:53:50.090Z","releaseDate":"2015-02-03T16:53:50.090Z","categories":["54d0fd1e095c470d00d16471","54d8b5e68934140d00496544","54db6361c6a4d40d0034b8f7","54db638208ea010d00ab1fdd","54db639008ea010d00ab1fde","54db6547c6a4d40d0034b8fd","54db83482092743700ea6ee1","54db84afc6a4d40d0034b93c","54db8805c6a4d40d0034b93f","54db8de9c6a4d40d0034b961","54db931ac6a4d40d0034b96d","54e49219e4365521006fd9ee","54e74fcc652d7c1900cbe737","54e74ffd3c1e111700d05762","54e77e0a523b1b2f00e6f313","54e784affdabe62500fcddcf","54e784fa523b1b2f00e6f319","54e785de8ae8911900cd42c5","54fdad6e660db63700c23b82","54fdff31f7b1202100a25e06"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-03-09T20:17:06.518Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":3,"body":"To import your data first you need to create a collection related to a database previously created. See [Creating a collection](doc:creating-a-collection) tutorial to learn how to create a collection where your data will be imported to. After create a collection you will be able to import your data.\n\nThe **goGeo** platform provides some tools to perform these tasks, you can use the Console or access some API endpoints. The follows enumerated sections describe ways to import your data:\n\n1. [Inserting a Batch of Documents by API](/v1.0/docs/importing-data#inserting-a-batch-of-documents-by-api);\n2. [Inserting Document by Document by API](/v1.0/docs/importing-data#inserting-document-by-document-by-api).\n\nTry it!\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Inserting a Batch of Documents by API\"\n}\n[/block]\nTo insert a batch of documents in a collection via API, you will first need your API-KEY. You will need to get it in the Console.\n\nWith the API-KEY in hands, you just need to do a POST request. You can do this using some tools. Below we can see example(s).\n\n# cURL\nThis insertion is made by importing a file containing the data. There are two types of format accepted by **goGeo** platform: CSV and Shapefile. Each one has their singularities. To a better understand of how this file types works on **goGeo** platform, check the Guide [**Data Impor**t](doc:data-insertion). Next, is presented a cURL example with each one of this types.\n\n**CSV:**\n\n Let's use the *URL* as ```https://www.dropbox.com/s/rw0q82cu8ll2qcu/basic.csv?dl=1``` in order to insert a sample data concerning five fictitious companies in Brazil.\n\nOpen a terminal and execute the follow command:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl -k --user {apikey}: -H \\\"Content-Type: application/json\\\" -XPOST \\\\\\n\\\"http://api.gogeo.io/1.0/imports\\\" -d '\\n{\\n  \\\"database\\\": \\\"{database_name}\\\",\\n  \\\"collection_name\\\": \\\"{collection_name}\\\",\\n  \\\"url\\\": \\\"https://www.dropbox.com/s/rw0q82cu8ll2qcu/basic.csv?dl=1\\\",\\n  \\\"metadata\\\" : {\\n    \\\"field_delimiter\\\" : \\\";\\\",\\n    \\\"row_delimiter\\\" : \\\"\\\\n\\\",\\n    \\\"header\\\" : true,\\n    \\\"geom\\\" : {\\n      \\\"type\\\" : \\\"latlon\\\",\\n      \\\"fields\\\" : [\\\"lat\\\", \\\"lon\\\"]\\n    },\\n    \\\"mapping\\\" : [\\n      [\\\"name\\\", \\\"string\\\"],\\n      [\\\"city\\\", \\\"string\\\"],\\n      [\\\"state\\\", \\\"string\\\"],\\n      [\\\"lat\\\", \\\"float\\\"],\\n      [\\\"lon\\\", \\\"float\\\"]\\n    ]\\n  }\\n}'\",\n      \"language\": \"curl\"\n    }\n  ]\n}\n[/block]\nThis will create a import data operation. Just replace *{apikey}* by your own API-KEY, *{database_name}* and *{collection_name}* by the names where you want to put these data.\n\nIf you open the CSV file, you will see there is five attributes (*name*, *city*, *state*, *lat*, *lon*) named in the header line and five lines with the attributes of each company.\n\nIn the *metadata* parameter we tell what is the data type of each attribute, the field delimiter, the line delimiter and if the file has a header line or not. We also give information about where is the geometry data. In this sample, the geometries are coordinate pairs. So, we use *latlon* as our geometry type and the *fields* section informs which attributes are going to be used as latitude and longitude respectively. \n\nIf your import was successful, your data is already in your collection.\n\n**Shapefile:**\n\nLet's use the *URL* as https://www.dropbox.com/s/q6vpwtlm8rc702w/es_go_municipios_18.tar.bz2?dl=1. \n\nNote that this *URL* is pointing to a compacted file. This file relates to the five files which compose the shapefile. The three necessary ones are the .shp, .dbf and .shx ones. The files already contain information about all attributes and geometry information in a well defined standard. For this reason, it is not required to inform the metadata parameter when inserting shapefiles.\n\nOpen a terminal and execute the follow command:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl -k --user {apikey}: -H \\\"Content-Type: application/json\\\" -XPOST \\\\\\n\\\"http://api.gogeo.io/1.0/imports\\\" -d '\\n{\\n  \\\"database\\\": \\\"{database_name}\\\",\\n  \\\"collection_name\\\": \\\"{collection_name}\\\",\\n  \\\"url\\\": \\\"hhttps://www.dropbox.com/s/q6vpwtlm8rc702w/es_go_municipios_18.tar.bz2?dl=1\\\"\\n}\",\n      \"language\": \"curl\"\n    }\n  ]\n}\n[/block]\nThis will create a import data operation. Just replace *{apikey}* by your own API-KEY, *{database_name}* and *{collection_name}* by the names where you want to put these data.\n\nCongratulations, you already imported your shapefile data in your collection.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Inserting Document by Document by API\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"body\": \"This just can be done after a first document import on collection.\"\n}\n[/block]\nTo insert a document in a collection via API, you will first need your API-KEY. You will need to get it in the Console, like the Figure 1.\n\nTo insert a document by document, it is necessary to send as JSON.\nWith the API-KEY in hands, you just need to do a POST request. You can do this using some tools. Below we can see an example.\n\n### cURL\n\nOpen a terminal;\n\nExecuting the follow command:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl -k --user {apikey}: -H \\\"Content-Type: application/json\\\" -XPOST\\n\\\"https://api.gogeo.io/1.0/databases/{database_name}/collections/{collection_name}/documents.json\\\" -d '\\n{\\n  \\\"json\\\": {\\n    \\\"geom\\\": {\\n      \\\"type\\\": \\\"Point\\\",\\n      \\\"coordinates\\\": [-118.141711, 34.181178]\\n    },\\n    \\\"properties\\\": {\\n      \\\"name\\\": \\\"Robert\\\",\\n      \\\"age\\\": 26\\n    }\\n  }\\n}'\",\n      \"language\": \"curl\"\n    }\n  ]\n}\n[/block]\nThat will insert a document with attributes *name* and *age* which contains the values *Robert* and *26*. Just replace *{apikey}* by your own API-KEY, *{database_name}* and *{collection_name}* by the names where you want to put these data.\n\nTo do this, its required that the database and the collection has already created.\n\nCongratulations, you already have insert your document on the collection.\n\n---\n[block:html]\n{\n  \"html\": \"<div class='div-middle'> \\n  <a href='#'>\\n    Top page &spades; </div>\\n  </a>\\n</div>\\n\\n<div class='div-back'> \\n  <a href='/v1.0/docs/creating-a-collection'>\\n    &laquo; Back \\n  </a>\\n</div>\\n\\n<div class='div-forward'> \\n  <a href='/v1.0/docs/creating-a-simple-map-to-see-your-data'>\\n    Next &raquo; </div>\\n  </a>\\n</div>\\n\\n<style>\\n\\t.div-back {\\n  \\tpadding-left: 15px;\\n\\t\\tmargin-top: -20px;\\n  }\\n  \\n  .div-middle {\\n  \\ttext-align: center;\\n\\t\\tmargin-top: -15px;\\n  }\\n  \\n  .div-forward {\\n  \\tfloat: right;\\n    padding-right: 15px;\\n\\t\\tmargin-top: -20px;\\n  }\\n</style>\"\n}\n[/block]","excerpt":"Importing your own data.","slug":"importing-data","type":"basic","title":"Importing data"}

Importing data

Importing your own data.

To import your data first you need to create a collection related to a database previously created. See [Creating a collection](doc:creating-a-collection) tutorial to learn how to create a collection where your data will be imported to. After create a collection you will be able to import your data. The **goGeo** platform provides some tools to perform these tasks, you can use the Console or access some API endpoints. The follows enumerated sections describe ways to import your data: 1. [Inserting a Batch of Documents by API](/v1.0/docs/importing-data#inserting-a-batch-of-documents-by-api); 2. [Inserting Document by Document by API](/v1.0/docs/importing-data#inserting-document-by-document-by-api). Try it! [block:api-header] { "type": "basic", "title": "Inserting a Batch of Documents by API" } [/block] To insert a batch of documents in a collection via API, you will first need your API-KEY. You will need to get it in the Console. With the API-KEY in hands, you just need to do a POST request. You can do this using some tools. Below we can see example(s). # cURL This insertion is made by importing a file containing the data. There are two types of format accepted by **goGeo** platform: CSV and Shapefile. Each one has their singularities. To a better understand of how this file types works on **goGeo** platform, check the Guide [**Data Impor**t](doc:data-insertion). Next, is presented a cURL example with each one of this types. **CSV:** Let's use the *URL* as ```https://www.dropbox.com/s/rw0q82cu8ll2qcu/basic.csv?dl=1``` in order to insert a sample data concerning five fictitious companies in Brazil. Open a terminal and execute the follow command: [block:code] { "codes": [ { "code": "curl -k --user {apikey}: -H \"Content-Type: application/json\" -XPOST \\\n\"http://api.gogeo.io/1.0/imports\" -d '\n{\n \"database\": \"{database_name}\",\n \"collection_name\": \"{collection_name}\",\n \"url\": \"https://www.dropbox.com/s/rw0q82cu8ll2qcu/basic.csv?dl=1\",\n \"metadata\" : {\n \"field_delimiter\" : \";\",\n \"row_delimiter\" : \"\\n\",\n \"header\" : true,\n \"geom\" : {\n \"type\" : \"latlon\",\n \"fields\" : [\"lat\", \"lon\"]\n },\n \"mapping\" : [\n [\"name\", \"string\"],\n [\"city\", \"string\"],\n [\"state\", \"string\"],\n [\"lat\", \"float\"],\n [\"lon\", \"float\"]\n ]\n }\n}'", "language": "curl" } ] } [/block] This will create a import data operation. Just replace *{apikey}* by your own API-KEY, *{database_name}* and *{collection_name}* by the names where you want to put these data. If you open the CSV file, you will see there is five attributes (*name*, *city*, *state*, *lat*, *lon*) named in the header line and five lines with the attributes of each company. In the *metadata* parameter we tell what is the data type of each attribute, the field delimiter, the line delimiter and if the file has a header line or not. We also give information about where is the geometry data. In this sample, the geometries are coordinate pairs. So, we use *latlon* as our geometry type and the *fields* section informs which attributes are going to be used as latitude and longitude respectively. If your import was successful, your data is already in your collection. **Shapefile:** Let's use the *URL* as https://www.dropbox.com/s/q6vpwtlm8rc702w/es_go_municipios_18.tar.bz2?dl=1. Note that this *URL* is pointing to a compacted file. This file relates to the five files which compose the shapefile. The three necessary ones are the .shp, .dbf and .shx ones. The files already contain information about all attributes and geometry information in a well defined standard. For this reason, it is not required to inform the metadata parameter when inserting shapefiles. Open a terminal and execute the follow command: [block:code] { "codes": [ { "code": "curl -k --user {apikey}: -H \"Content-Type: application/json\" -XPOST \\\n\"http://api.gogeo.io/1.0/imports\" -d '\n{\n \"database\": \"{database_name}\",\n \"collection_name\": \"{collection_name}\",\n \"url\": \"hhttps://www.dropbox.com/s/q6vpwtlm8rc702w/es_go_municipios_18.tar.bz2?dl=1\"\n}", "language": "curl" } ] } [/block] This will create a import data operation. Just replace *{apikey}* by your own API-KEY, *{database_name}* and *{collection_name}* by the names where you want to put these data. Congratulations, you already imported your shapefile data in your collection. [block:api-header] { "type": "basic", "title": "Inserting Document by Document by API" } [/block] [block:callout] { "type": "warning", "body": "This just can be done after a first document import on collection." } [/block] To insert a document in a collection via API, you will first need your API-KEY. You will need to get it in the Console, like the Figure 1. To insert a document by document, it is necessary to send as JSON. With the API-KEY in hands, you just need to do a POST request. You can do this using some tools. Below we can see an example. ### cURL Open a terminal; Executing the follow command: [block:code] { "codes": [ { "code": "curl -k --user {apikey}: -H \"Content-Type: application/json\" -XPOST\n\"https://api.gogeo.io/1.0/databases/{database_name}/collections/{collection_name}/documents.json\" -d '\n{\n \"json\": {\n \"geom\": {\n \"type\": \"Point\",\n \"coordinates\": [-118.141711, 34.181178]\n },\n \"properties\": {\n \"name\": \"Robert\",\n \"age\": 26\n }\n }\n}'", "language": "curl" } ] } [/block] That will insert a document with attributes *name* and *age* which contains the values *Robert* and *26*. Just replace *{apikey}* by your own API-KEY, *{database_name}* and *{collection_name}* by the names where you want to put these data. To do this, its required that the database and the collection has already created. Congratulations, you already have insert your document on the collection. --- [block:html] { "html": "<div class='div-middle'> \n <a href='#'>\n Top page &spades; </div>\n </a>\n</div>\n\n<div class='div-back'> \n <a href='/v1.0/docs/creating-a-collection'>\n &laquo; Back \n </a>\n</div>\n\n<div class='div-forward'> \n <a href='/v1.0/docs/creating-a-simple-map-to-see-your-data'>\n Next &raquo; </div>\n </a>\n</div>\n\n<style>\n\t.div-back {\n \tpadding-left: 15px;\n\t\tmargin-top: -20px;\n }\n \n .div-middle {\n \ttext-align: center;\n\t\tmargin-top: -15px;\n }\n \n .div-forward {\n \tfloat: right;\n padding-right: 15px;\n\t\tmargin-top: -20px;\n }\n</style>" } [/block]