Open In Colab Open this Colab for an interactive tutorial about how to import annotations on document data.

Open a Colab to go through the exercise of importing geospatial annotations.

Supported annotations

Point

point_annotation = ObjectAnnotation(
  name = "point_geo",
  value = Point(x=-99.21052827588443, y=19.405662413477728),
)
point_annotation_ndjson = {
    "name": "point_geo",
    "point": {
         "x": -99.21052827588443,
         "y": 19.405662413477728
     }
}

Polyline

# Coordinates in the desired EPSG coordinate system
coords = [[-99.2257610436396,19.418710777269197],[-99.22610441645385,19.341320919070036],[-99.1464419235419,19.341644802568833],[-99.14781541479901,19.420653145480912],[-99.22439165216781,19.42047504824125],[-99.1989820639114,19.414324129199997]]
line_points = []

for sub in coords: 
  line_points.append(Point(x=sub[0], y=sub[1]))

# Python Annotation 
polyline_annotation = ObjectAnnotation(
  name = "polyline_geo",
  value = Line(points=line_points),
)
## Coordinates in the desired EPSG coordinate system
coords = [[-99.2257610436396,19.418710777269197],[-99.22610441645385,19.341320919070036],[-99.1464419235419,19.341644802568833],[-99.14781541479901,19.420653145480912],[-99.22439165216781,19.42047504824125],[-99.1989820639114,19.414324129199997]]
line_points_ndjson = []

for sub in coords: 
  line_points_ndjson.append({"x":sub[0], "y":sub[1]})

polyline_annotation_ndjson = {
    "name": "polyline_geo",
    "line": line_points_ndjson
}

Polygon

# Coordinates in the desired EPSG coordinate system
coords_polygon = [[-99.2103219219407,19.382085377579806],[-99.21375304694426,19.362328387802638],[-99.19006492831323,19.36297607074792],[-99.19281196088781,19.381437207301936],[-99.2103219219407,19.382085377579806]]
polygon_points = []

for sub in coords_polygon: 
  polygon_points.append(Point(x=sub[0], y=sub[1]))

polygon_annotation = ObjectAnnotation(
  name = "polygon_geo",
  value = Polygon(points=polygon_points),
)

# Coordinates in the desired EPSG coordinate system
coords_polygon = [[-99.2103219219407,19.382085377579806],[-99.21375304694426,19.362328387802638],[-99.19006492831323,19.36297607074792],[-99.19281196088781,19.381437207301936],[-99.2103219219407,19.382085377579806]]
polygon_points_ndjson = []

for sub in coords_polygon: 
  polygon_points_ndjson.append({"x":sub[0], "y":sub[1]})


polygon_annotation_ndjson = {
    "name": "polygon_geo",
    "polygon": polygon_points_ndjson
}

Bounding box

bbox_top_left = Point(x=-99.21052827588443, y=19.405662413477728)
bbox_bottom_right = Point(x=-99.20534818927473, y=19.400498983095076)

# Python Annotation
bbox_annotation = ObjectAnnotation(
  name = "bbox_geo",
  value = Rectangle(start=bbox_top_left, end=bbox_bottom_right)
)

coord_object = {
      "coordinates": [
        [
            [
                -99.210528,
                19.405662
            ],
            [
                -99.210528,
                19.400499
            ],
            [
                -99.205348,
                19.400499
            ],
            [
                -99.205348,
                19.405662
            ],
            [
                -99.210528,
                19.405662
            ]
          ]
        ]
      
    }

bbox_annotation_ndjson = {
    "name" : "bbox_geo",
    "bbox" : {
        'top': coord_object["coordinates"][0][1][1],
        'left': coord_object["coordinates"][0][1][0],
        'height': coord_object["coordinates"][0][3][1] - coord_object["coordinates"][0][1][1],        
        'width': coord_object["coordinates"][0][3][0] - coord_object["coordinates"][0][1][0]
    }
}

Segmentation mask

Not supported

Classification - radio (single choice)

radio_annotation = ClassificationAnnotation(
    name="radio_question_geo", 
    value=Radio(answer=ClassificationAnswer(name="first_radio_answer"))
)
radio_annotation_ndjson = {
    "name": "radio_question_geo",
    "answer": { "name": "first_radio_answer"}
}

Classification - checklist (multi-choice)

checklist_annotation = Checklist(answer=[ClassificationAnswer(name="first_checklist_answer"),ClassificationAnswer(name="second_checklist_answer")])

# nested checklist under a bounding box object annotation
bbox_with_checklist_subclass = ObjectAnnotation(
    name="bbox_checklist_geo",
    value=Rectangle(
        start=Point(x=-99.17322500305542, y=19.40640857294981), # Top left
        end=Point(x=-99.19211050784055, y=19.398962049791287), # Bottom right
    ),
    classifications=[
        ClassificationAnnotation(
            name="checklist_class_name",
            value=Checklist(
                answer=[ClassificationAnswer(name="first_checklist_answer")]
            )
        )
    ]
)
# Global classification
radio_annotation_ndjson = {
    "name": "radio_question_geo",
    "answer": { "name": "first_checklist_answer"}
}

# nested checklist under a bounding box object annotation
coord_object_checklist = {
    "coordinates": [
        [
          [
              -99.173225,
              19.406409
          ],
          [
              -99.173225,
              19.398962
          ],
          [
              -99.192111,
              19.398962
          ],
          [
              -99.192111,
              19.406409
          ],
          [
              -99.173225,
              19.406409
          ]
      ]
    ]          
}

bbox_with_checklist_subclass_ndjson = {
    "name": "bbox_checklist_geo", 
    "classifications": [{
        "name": "checklist_class_name",
        "answer": [
            { "name":"first_checklist_answer" }
        ]   
    }],
    "bbox": {
        'top': coord_object_checklist["coordinates"][0][1][1],
        'left': coord_object_checklist["coordinates"][0][1][0],
        'height': coord_object_checklist["coordinates"][0][3][1] - coord_object_checklist["coordinates"][0][1][1],        
        'width': coord_object_checklist["coordinates"][0][3][0] - coord_object_checklist["coordinates"][0][1][0]
    }
}

Classification - free-form text

text_annotation = ClassificationAnnotation(value=Text(answer="sample text"), name="text")

# nested free form text
bbox_with_free_text_subclass = ObjectAnnotation(
    name="bbox_text_geo",
    value=Rectangle(
        start=Point(x=-99.1818093234123, y=19.34941781372347), # Top left
        end=Point(x=-99.15399612545598, y=19.357514306583965), # Bottom right
    ),
    classifications=[
        ClassificationAnnotation(
            name="free_text_geo",
            value=Text(answer="sample text")
        )
    ]
)
radio_annotation_ndjson = {
    "name": "free_text_question_geo",
    "answer": "sample text"
}

# nested free-form text under a bounding box object annotation
coord_object_checklist = {
    "coordinates": [
        [
          [
              -99.173225,
              19.406409
          ],
          [
              -99.173225,
              19.398962
          ],
          [
              -99.192111,
              19.398962
          ],
          [
              -99.192111,
              19.406409
          ],
          [
              -99.173225,
              19.406409
          ]
      ]
    ]          
}
bbox_with_free_text_subclass_ndjson = {
    "name":"bbox_text_geo",
    "classifications": [{
        "name": "free_text_geo",
        "answer": "sample text"
    }],
    "bbox": {
        'top': coord_object_text["coordinates"][0][1][1],
        'left': coord_object_text["coordinates"][0][1][0],
        'height': coord_object_text["coordinates"][0][3][1] - coord_object_text["coordinates"][0][1][1],        
        'width': coord_object_text["coordinates"][0][3][0] - coord_object_text["coordinates"][0][1][0]
    }
}